-
Notifications
You must be signed in to change notification settings - Fork 333
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
base: 6
Are you sure you want to change the base?
API Move some code to framework to be reusable #3022
Conversation
4e32958
to
f7b0fbf
Compare
code/Model/SiteTree.php
Outdated
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 = []; | ||
|
There was a problem hiding this comment.
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.
private static $default_child = "Page"; | ||
private static $default_child = Page::class; |
There was a problem hiding this comment.
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.
c5b3124
to
0148368
Compare
* @config | ||
* @var string | ||
*/ | ||
private static $default_parent = null; |
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
tests/php/Model/SiteTreeTest.php
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
// We need to flush the static cache so we don't have a stale reference to $page in $virtual->components | ||
$virtual->flushCache(); |
There was a problem hiding this comment.
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.
0148368
to
0e6a639
Compare
Some of this code needs to be usable on classes other than SiteTree with the CMSMain refactoring.
0e6a639
to
8b2df92
Compare
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 aDataObject
record which has theHierarchy
extension applied.Issue
SiteTree
inCMSMain
#2947