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 Move some code to framework to be reusable #3022

Merged

Conversation

GuySartorelli
Copy link
Member

This logic is used by CMSMain but needs to be callable on any hierarchical model.

See the corresponding framework PR to see where this code is going.

See the overall refactoring PR (or just look in CMSMain) to see where it's being used and why it needs to be moved. Basically, anything CMSMain calls needs to be available on a DataObject record which has the Hierarchy extension applied.

Issue

Comment on lines 131 to 142
private static $allowed_children = [
SiteTree::class
];

/**
* Used as a cache for `SiteTree::allowedChildren()`
* Drastically reduces admin page load when there are a lot of page types
* @var array
*/
protected static $_allowedChildren = [];

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to Hierarchy in framework.

Comment on lines -161 to +136
private static $default_child = "Page";
private static $default_child = Page::class;
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated cleanup - this is a class name, not an arbitrary string.

@GuySartorelli GuySartorelli force-pushed the pulls/6/move-to-framework branch 2 times, most recently from c5b3124 to 0148368 Compare November 11, 2024 20:39
* @config
* @var string
*/
private static $default_parent = null;
Copy link
Member Author

Choose a reason for hiding this comment

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

default_parent moved to Hierarchy in framework.

Comment on lines -170 to +145
private static $default_classname = "Page";

/**
* The default parent class for this page.
* Note: Value might be cached, see {@link $allowed_chilren}.
*
* @config
* @var string
*/
private static $default_parent = null;
private static $default_classname = Page::class;
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated cleanup - default_classname is a class name, not an arbitrary string.

@@ -330,6 +296,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi

private static $default_sort = "\"Sort\"";

private static string $sort_field = 'Sort';
Copy link
Member Author

Choose a reason for hiding this comment

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

New config from Hierarchy in framework. This allows CMSMain and Hierarchy both to reason about arbitrary models without requiring a hardcoded specific field name for sorting.

* @config
* @var string
*/
private static $description = null;
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to DataObject in framework and renamed to a more specific class_description

*/
private static $base_description = 'Generic content page';
private static string $base_class_description = 'Generic content page';
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to match the description => class_description renaming

*
* @return array
*/
public function provideI18nEntities()
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved the description entity to DataObject in framework. This method is no longer needed in this class.

/**
* Get the record to check against for allowed children check in validation.
*/
public function getRecordForAllowedChildrenValidation(): SiteTree
Copy link
Member Author

Choose a reason for hiding this comment

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

See Hierarchy::updateValidate() in framework

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests moved along with the logic they're testing

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 class was only ever used in a test that got moved

Comment on lines +523 to +524
// We need to flush the static cache so we don't have a stale reference to $page in $virtual->components
$virtual->flushCache();
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 test was really flakey - it relied on the fact that we hadn't fetched the CopyContentFrom has_one record yet. Changes in this and the framework PR resulted in it being fetched so we had a stale reference to the $page record that got originally saved (with the "published title" text).

We have to clear that out of the static cache here, so that we fetch the record with the "original" text so that can be copied through to our virtual page on write.

@GuySartorelli GuySartorelli force-pushed the pulls/6/move-to-framework branch 2 times, most recently from 0e6a639 to 8b2df92 Compare November 14, 2024 04:37
@GuySartorelli GuySartorelli marked this pull request as ready for review November 14, 2024 04:40
@GuySartorelli GuySartorelli force-pushed the pulls/6/move-to-framework branch from 8b2df92 to 2f9e750 Compare November 20, 2024 02:34
@@ -3008,6 +2709,7 @@ public function getTreeTitle()
{
$children = $this->creatableChildPages();
$flags = $this->getStatusFlags();
$this->extend('updateStatusFlagsForTreeTitle', $flags);
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 new extension hook allows fluent to exclude its flags from the site tree list, because they look awful there.
In the next set of PRs after this one, it'll be on CMSMain instead, but for now SiteTree directly handles how things look in that tree.

@GuySartorelli GuySartorelli force-pushed the pulls/6/move-to-framework branch 2 times, most recently from 2b2fcea to 52a3e72 Compare November 21, 2024 21:19
Some of this code needs to be usable on classes other than SiteTree with
the CMSMain refactoring.
@GuySartorelli GuySartorelli force-pushed the pulls/6/move-to-framework branch from 52a3e72 to 34a10aa Compare November 21, 2024 21:19
@emteknetnz emteknetnz merged commit 0778d7b into silverstripe:6 Nov 26, 2024
6 of 12 checks passed
@emteknetnz emteknetnz deleted the pulls/6/move-to-framework branch November 26, 2024 03:41
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