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

Open
wants to merge 1 commit into
base: 6
Choose a base branch
from

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.

* @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.

Some of this code needs to be usable on classes other than SiteTree with
the CMSMain refactoring.
@GuySartorelli GuySartorelli marked this pull request as ready for review November 14, 2024 04:40
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.

1 participant