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

API Make CMSMain more generic #3035

Merged

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli commented Dec 8, 2024

Replaces #3017

  • Remove hardcoded references to pages and SiteTree
  • Remove assumption that records are versioned
  • Remove or validate assumptions about methods on the model class
  • Improve general architecture of CMSMain
  • Update localisation keys to be more standardised and to live in more appropriate places

Relies on changes in silverstripe/silverstripe-admin#1837

Issue

@GuySartorelli GuySartorelli marked this pull request as draft December 8, 2024 20:28
@GuySartorelli GuySartorelli force-pushed the pulls/6.0/generic-cmsmain branch 3 times, most recently from 8365dd3 to 83bd75e Compare December 10, 2024 23:56
Comment on lines +183 to +185
if (!DataObject::singleton($modelClass)->getSortField()) {
throw new LogicException($modelClass . ' must define a sort field');
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is debatable - I've got it here mostly because I don't want to rework the UI elements that assume records can be sorted. Realistically there probably isn't much value in using this UI if your record isn't sortable anyway.

Comment on lines +282 to +285
$controller = $this;
if (static::class !== CMSMain::class) {
$controller = CMSMain::singleton();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little untidy but necessary for now. Will be cleared up as part of #2951 which removes the CMSMain subclasses.

Comment on lines +857 to +860
// Hardcoded check for SiteTree
// Ideally CMSMain will get an abstract parent class with all of the generic logic,
// and then this conditional check can be removed in CMSMain itself.
if (is_a($this->getModelClass(), SiteTree::class, true)) {
return SiteConfig::current_site_config()->canCreateTopLevel();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing that will be tidied up as part of #2951

Comment on lines +873 to +876
// Hardcoded check for SiteTree
// Ideally CMSMain will get an abstract parent class with all of the generic logic,
// and then this conditional check can be removed in CMSMain itself.
if (is_a($this->getModelClass(), SiteTree::class, true)) {
return (bool) Permission::check('SITETREE_REORGANISE');
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing that will be tidied up as part of #2951

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole class was just a couple of templates and a form. It's been moved into CMSMainAddForm, the associated template, and an action on CMSMain to get the form.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole class was effectively just a placeholder to render some templates. Those templates have been distilled into CMSMain_LeftPanel.ss which is included in the appropriate places in CMSMain_Content.ss and CMSMain_Tools.ss

Note I'm not removing CMSPageEditController in this PR because it wasn't removable when the bulk of this work was done. That can be removed in #2951 which has an explicit AC for that purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was quite a lot of duplication between this and the old CMSPagesController templates. That duplication is now distilled into the CMSMain_LeftPanel.ss template.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just had a pointless include in it

Comment on lines -1007 to -1023
/**
* This provides information required to generate the search form
* and can be modified on extensions through updateSearchContext
*
* @return \SilverStripe\ORM\Search\SearchContext
* @deprecated 5.4.0 Will be replaced with SilverStripe\CMS\Model\SiteTree::getDefaultSearchContext().
*/
public function getSearchContext()
{
Deprecation::notice('5.4.0', 'Will be replaced with ' . SiteTree::class . '::getDefaultSearchContext().');
$context = SiteTree::singleton()->getDefaultSearchContext();

$this->extend('updateSearchContext', $context);

return $context;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed - this is just basically adding an extra extension hook on top of getDefaultSearchContext().
If we think that's valuable, it should be added to DataObject::getDefaultSearchContext() instead - though the fact that method doesn't already have an extension hook implies one isn't needed there. People can also override getDefaultSearchContext() in their Page or other classes to return different search contexts.

Comment on lines -212 to -217
if (!$parentID && isset($data['Parent'])) {
$page = SiteTree::get_by_link($data['Parent']);
if ($page) {
$parentID = $page->ID;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific piece of code isn't replicated in the new form or action.
It was originally introduced in c247db5 which doesn't really make it clear what the intended use case of it is. It doesn't seem to be needed at all, nothing that I can see sets the Parent key in the data array.

@GuySartorelli GuySartorelli marked this pull request as ready for review December 11, 2024 23:13
Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except now there's a merge conflict! :-)

@GuySartorelli GuySartorelli force-pushed the pulls/6.0/generic-cmsmain branch from 83bd75e to 28ca200 Compare December 12, 2024 04:15
Remove hardcoded references to pages and SiteTree
Remove assumption that records are versioned
Remove or validate assumptions about methods on the model class
Improve general architecture of CMSMain
@GuySartorelli GuySartorelli force-pushed the pulls/6.0/generic-cmsmain branch from 28ca200 to b92ad3a Compare December 12, 2024 04:16
@emteknetnz emteknetnz merged commit 5336a99 into silverstripe:6.0 Dec 12, 2024
4 of 15 checks passed
@emteknetnz emteknetnz deleted the pulls/6.0/generic-cmsmain branch December 12, 2024 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants