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
7 tasks done
GuySartorelli opened this issue May 30, 2024 · 0 comments
Open
7 tasks done

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?

Decision for the above: Leave that as is for now. Part of #2951 will include keeping the site name being returned from CMSMain while the generic abstract class returns a generic value.

PRs

Quick cleanup PR:

This PR removes the provideI18nEntities() entry for a localisation key that was just always in the wrong place. More details are in the PR itself.
It doesn't block anything so even if you have questions about this PR, please also review any other PRs below that are ready for review.

Moving Code Around PRs:

There's a bunch of stuff that CMSMain relies on which is currently only on SiteTree. This set of PRs moves most of that stuff around so that it can be reliably called on any DataObject class which has the Hierarchy extension, which is the criteria for models to be used in CMSMain.

You can see these changes in context in the "Main PRs" section

CMS 5 PRs

Reassign to Guy after merging these so they can rebase the CMS 6 PRs on top

CMS 6 PRs

Kitchen Sink CI

Reassign to Guy once these PRs are merged so they can rebase the main PRs and get those ready for the review cycle.

Main PRs:

CMS 5 PRs

TBD

Reassign to Guy after merging these so they can rebase the CMS 6 PRs on top

CMS 6 PRs

@GuySartorelli GuySartorelli added this to the Silverstripe CMS 6 milestone May 30, 2024
This was referenced Oct 16, 2024
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

3 participants