-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPIKE Analyse how LeftAndMain and CMSMain are put together and how they could work better #2933
Comments
|
method name | description | recommendation |
---|---|---|
getRecord() |
Get a record by ID, based on the tree_class . LeftAndMain is the only class that seems to override this, and that's to work with the history viewer (getting specific versions of records). Doesn't seem to be used much, but probably not worth removing it. |
Leave as is. |
save() |
Action for clicking "save" button on a form. Almost nothing uses it directly, and anything that does will get its own superclass as we'll see further down. | make abstract |
getNewItem() |
Only called in the save() method - CMSMain calls it but it also overrides it with its own implementation. Probably not useful, uses an antipattern of creating an item with a specific ID. |
Delete it. Use injector or ::create() directly for the few places that call this method. |
delete() |
Action for clicking "delete" button on a form. ModelAdmin doesn't use it 'cause that's handled by GridField . CMSMain overrides it. SiteConfig and Reports don't have a delete button, and AssetAdmin` does stuff in its own funky graphql way instead. Maybe this is useful for some custom functionality? |
Make it abstract and let it be implemented anywhere that needs it (same deal as save() above) |
getEditForm() |
Makes the form for that admin section. Only seems to be used by CMSMain (and its subclasses) and CMSProfileController - which both make sense, they only manage a single class right now. Interestingly not used by ReportAdmin or SiteConfigLeftAndMain |
make abstract - it's not used widely enough to be useful at this level, but could be implemented elsewhere. That separate implementation will be discussed further down (same deal as save() above) |
batchactions() |
Seems to only be used in sitetree. Perhaps a future enhancement would be to make these somehow usable in a flexible way so we can have colymba/GridFieldBulkEditingTools and asset admin batch actions using this logic, but we can look at it again if/when we do that. AssetAdmin does register a batch action with the CMSBatchActionHandler but that seems to be dead code. |
Move to CMSMain directly (not `HierarchicalModelAdmin - making batch actions generic and moving it to a higher superclass can be a follow-on work later on) |
Remove the tree_class
config in favour of an abstract getModelClass()
method, which returns whatever the current class is. Some LeftAndMain
subclasses will always return the same class name (e.g. ReportAdmin
would always return Report::class
) but some would return an appropriate class based on the request (like ModelAdmin::getModelClass
).
Additional recommendations
There's a client_debugging
config which is only used to enable something in redux - we should either:
- Use this more, and have more debug output from js, or
- Remove the config and either remove whatever it's doing with redux (if it's not worth keeping) or just always do whatever it's doing in redux when in dev mode (if it is worth keeping).
Specific methods
- Delete
printable()
- Delete
getNewItem()
and just use injector or the::create()
method directly. It's an anti-pattern to make a new item with a specific ID. - Delete
LinkPreview()
and its usage in templates and any JS/CSS related to it - seems to be a legacy way to get the preview URL into the preview panel - Delete
SwitchView()
- isn't used, looks legacy - Delete
SiteConfig()
method -silverstripe/siteconfig
shouldn't be a dependency of admin, and you can get the current siteconfig both via PHP and in templates with methods provided by that module directly. - Delete
ApplicationLink()
- not used - Remove
AddForm
fromallowed_actions
- there's no corresponding method - Move everything related to batch actions into
CMSMain
since that's the only place that uses it - Regarding
currentPageID()
and its associated code, rename tocurrentRecordID()
(or probably evencurrentRecord()
and keep a reference to the actualDataObject
object rather than just the ID) and either:- Find a way to make it work with all admins (e.g. modeladmin gridfield edit forms as well) - and probably turn it into a stack rather than a single value
- Means there's an easy way to get the current record being edited, and any records that needed to be accessed to drill down to it (aka its "parents"), but is meaningless if we don't use it wherever we can ourselves
- Move this to a class that can be a superclass of
SiteConfigLeftAndMain
for dealing with only a single record (more details about that lower down)
- Find a way to make it work with all admins (e.g. modeladmin gridfield edit forms as well) - and probably turn it into a stack rather than a single value
- Delete
LeftAndMain_SearchFilter
- it's only implemented byCMSSiteTreeFilter
and even then only for a single form field. It was probably intended to be a way to customiseSearchContext
but doesn't seem to be used in the end. - Move
getSearchFilter
toCMSMain
or even intoSiteTree
since it's related toSiteTree
's searchable fields which should work the same in a gridfield as they do in this controller
New abstract AdminRouteController
class
Or, maybe it's not abstract and this is all added to the existing AdminRootController
. Either way is fine.
This class would handle permissions and anything you're likely to want in a generic controller that has a /admin/*
route.
It becomes the superclass for LeftAndMain
. Any time someone wants to check if the current controller is a CMS controller they can simple check if it's an instance of AdminRouteController
.
AdminRootController::rules()
and AdminRootController::add_rule_for_controller()
need to be updated to include routing for all non-abstract subclasses of AdminRouteController
.
Methods that go in here
jsonSuccess()
jsonError()
canView()
getRequiredPermissions()
- Some parts of
init()
- set locale and everything before that
- permissions stuff
- set stage (if
Versioned
module exists) - may need setting theme in case the custom controller wants to render out a template
- probably don't want the requirements js stuff
- no session ping
- no combined config
- no WYSIWYG stuff
- Check if
handleRequest()
validation exception catching makes sense here - if so, keep that part of this method here, if not leave that for a subclass.- Find out what the
X-*
headers are used for and include them in this class if it'd be useful for generic purposes
- Find out what the
redirect()
Link()
providePermissions()
New abstract FormSchemaAdmin
class, extends AdminRouteController
This becomes a superclass for classes like LinkFieldController
that are intended for use with form schema modal forms.
Note that there's additional formschema changes below - see ModalController
.
Methods that go in here
getFormSchema()
setFormSchema()
schema()
methodSchema()
getSchemaRequested()
(if it's even needed)getSchemaResponse()
- Anything from
handleRequest()
that makes sense here (e.g. theValidationException
handling probably fits here) save()
if it's needed for formschema modal forms to workdelete()
if it's needed or usable for formschema modal formsEditForm()
and/orgetEditForm()
if they're used by formschema formsEmptyForm()
if it's still needed bydelete()
, though ideally delete should close the modal instead of returning an empty form
|
ModelAdmin
|
New superclass for single-record
|
Aside from all that, the following are currently handled differently between
In particular, removing |
High level tl;drRestructuringThe actual names of classes don't matter here - I just needed a way to refer to everything. We can change those during implementation. Each of these numbered points essentially becomes its own card, though the
Benefits
Future AC breaking changes that could be done afterward
|
Created new epic with issues linked to it for all of the above refactorings. |
CMSMain, LeftAndMain, ModelAdmin and other related Admin controllers have been around and have accumulated quite a bit of technical debt.
Timebox
3 days
Objectives of this SPIKE
Related cards
POC PRs
For demonstrative purposes only
The text was updated successfully, but these errors were encountered: