Skip to content
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

Don't hardcode SiteTree in CMSMain #2947

Open
GuySartorelli opened this issue May 30, 2024 · 0 comments
Open

Don't hardcode SiteTree in CMSMain #2947

GuySartorelli opened this issue May 30, 2024 · 0 comments

Comments

@GuySartorelli
Copy link
Member

GuySartorelli commented May 30, 2024

CMSMain has a tree_class configuration property which is sometimes referenced - but sometimes SiteTree is explicitly hardcoded.
The hardcoded references and the assumptions about using SiteTree should be removed.

Benefits

  • opens a path for further refactoring to allow other hierarchical data to be displayed in a hierarchical way
  • opens a path to 'demistify' SiteTree so it becomes just another subclass of DataObject rather than having its own code paths in admin
  • opens a path to reduce code/feature duplication across admin and cms modules (e.g. the search UI, sending toasts, handling tabs/breadcurmbs and more)

Related

Notes

  • There are many ways to make calls to SiteTree methods/properties more generic, such as:
    • Implementing a method on CMSMain that calls that method if it exists, but falls back on other things - e.g. get MenuTitle if there is one, but fall back on Title
    • Moving the main implementation of the method from SiteTree into CMSMain, and invoking an extension hook on the record (probably with invokeWithExtensions()) to allow updating the value
  • Don't forget there's both a tree view and a list view! Both of these need to work and have their strings updated.

Acceptance criteria

  • A getModelClass() method is implemented, which returns the value stored in the tree_class configuration property
  • All hardcoded references to SiteTree or Page use the getModelClass() method instead (including subclasses of CMSMain)
  • Nothing assumes the model has the Versioned extension
  • Whenever CMSMain, one of its subclasses, or a template tries to call a method or fetch a property that is explicitly implemented on SiteTree, this is handled in a generic way
    • If any method/property is explicitly required which isn't provided by the DataObject class or the Hierarchy extension, throw clear exceptions if they're missing. One example (and probably the only case) is CMSEditLink.
  • In an appropriate place (maybe init()), a clear exception is thrown if the model class doesn't meet requirements to be used in CMSMain (i.e. doesn't have the Hierarchy extension applied, or is missing a method/property that is explicitly required for CMSMain to work)
  • Strings which assume SiteTree is being used are updated to pull from whatever model is used.
    • e.g. "Page type", "Add page", "Choose where to create this page", "Pages", etc.
  • With exception of the history tab, filtering the tree list, and batch actions (which will each be handled separately), all functionality in CMSMain works with TaxonomyTerm (when that class has the CMSEditLinkExtension extension applied - see config in the description of the POC PR)

TO DECIDE

  • Currently the site name (defined in siteconfig) is displayed as the root of the tree. This makes sense for pages but probably not for other models. What should be the root of the tree for non-page models?
    • Should it be configurable?
    • Should there be no root?
    • Should we just leave it as the site name for now and change it later if we feel like it?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants