Hierarchy
class Hierarchy extends Extension (View source)
DataObjects that use the Hierarchy extension can be be organised as a hierarchy, with children and parents. The most obvious example of this is SiteTree.
Properties
protected | T | $owner | The object this extension is applied to. |
from Extension |
protected static | array | $cache_numChildren | A cache used by numChildren(). |
|
protected static | array | $cache_allowedChildren | Used as a cache for allowedChildren() Drastically reduces admin page load when there are a lot of subclass types |
|
int | $ParentID |
Methods
Called when this extension is added to a particular class
Temporarily modify the owner. The original owner is ensured to be restored
Clear the current owner, and restore extension to the state prior to the last setOwner()
Helper method to strip eval'ed arguments from a string that's passed to DataObject::$extensions or Object::add_extension().
Invoke extension point. This will prefer explicit extend
prefixed
methods.
Validate the owner object - check for existence of infinite loops.
Get a list of this DataObject's and all it's descendants ID, and put them in $idList.
Duplicates each child of this record recursively and returns the top-level duplicate record.
Return all children, including those that have been deleted but are still in live.
Return all the children that this page had, including pages that were deleted from both stage & live.
Return the number of children that this page ever had, including pages that were deleted.
Return the number of direct children. By default, values are cached after the first invocation. Can be augmented by augmentNumChildrenCountQuery().
Pre-populate any appropriate caches prior to rendering a tree.
Pre-populate the cache for Versioned::get_versionnumber_by_stage() for a list of record IDs, for more efficient database querying. If $idList is null, then every record will be pre-cached.
Returns the class name of the default class for children of this page.
Returns the class name of the default class for the parent of this page.
Returns an array of the class names of classes that are allowed to be children of this class.
Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?
Return children in the stage site.
Return children in the live site, if it exists.
Get this object's parent, optionally filtered by an SQL clause. If the clause doesn't match the parent, nothing is returned.
Return all the parents of this class in a set ordered from the closest to furtherest parent.
Returns a human-readable, flattened representation of the path to the object, using its Title attribute.
Get the title that will be used in TreeDropdownField and other tree structures.
Returns true if the current user can add children to this page.
Block creating children not allowed for the parent type
Details
__construct()
No description
static
add_to_class(string $class, string $extensionClass, mixed $args = null)
Called when this extension is added to a particular class
setOwner(object $owner)
Set the owner of this extension.
mixed
withOwner(mixed $owner, callable $callback, array $args = [])
Temporarily modify the owner. The original owner is ensured to be restored
clearOwner()
Clear the current owner, and restore extension to the state prior to the last setOwner()
T
getOwner()
Returns the owner of this extension.
static string
get_classname_without_arguments(string $extensionStr)
Helper method to strip eval'ed arguments from a string that's passed to DataObject::$extensions or Object::add_extension().
mixed
invokeExtension(object $owner, string $method, array ...$arguments)
Invoke extension point. This will prefer explicit extend
prefixed
methods.
static
get_extra_config($class, $extension, $args)
No description
protected
updateValidate(ValidationResult $validationResult)
Validate the owner object - check for existence of infinite loops.
int[]
getDescendantIDList()
Get a list of this DataObject's and all it's descendants IDs.
protected
loadDescendantIDListInto(array $idList, DataObject|Hierarchy $node = null)
Get a list of this DataObject's and all it's descendants ID, and put them in $idList.
DataObject
duplicateWithChildren()
Duplicates each child of this record recursively and returns the top-level duplicate record.
If there is a sort field, new sort values are set for the duplicates to retain their sort order.
DataObject&static>
Children()
Get the children for this DataObject filtered by canView()
DataObject&static>
AllChildren()
Return all children, including those 'not in menus'.
DataObject&static>
AllChildrenIncludingDeleted()
Return all children, including those that have been deleted but are still in live.
- Deleted children will be marked as "DeletedFromStage"
- Added children will be marked as "AddedToStage"
- Modified children will be marked as "ModifiedOnStage"
- Everything else has "SameOnStage" set, as an indicator that this information has been looked up.
DataObject&static>
AllHistoricalChildren()
Return all the children that this page had, including pages that were deleted from both stage & live.
int
numHistoricalChildren()
Return the number of children that this page ever had, including pages that were deleted.
int
numChildren(bool $cache = true)
Return the number of direct children. By default, values are cached after the first invocation. Can be augmented by augmentNumChildrenCountQuery().
prepopulateTreeDataCache(DataList|array $recordList = null, array $options = [])
Pre-populate any appropriate caches prior to rendering a tree.
This is used to allow for the efficient rendering of tree views, notably in the CMS. In the case of Hierarchy, it caches numChildren values. Other extensions can provide an onPrepopulateTreeDataCache(DataList $recordList = null, array $options) methods to hook into this event as well.
static
prepopulate_numchildren_cache(string $baseClass, array $idList = null)
Pre-populate the cache for Versioned::get_versionnumber_by_stage() for a list of record IDs, for more efficient database querying. If $idList is null, then every record will be pre-cached.
string|null
defaultChild()
Returns the class name of the default class for children of this page.
Note that this is intended for use with CMSMain and may not be respected with other model management methods.
string|null
defaultParent()
Returns the class name of the default class for the parent of this page.
Note that this is intended for use with CMSMain and may not be respected with other model management methods. Doesn't check the allowedChildren config for the parent class.
array
allowedChildren()
Returns an array of the class names of classes that are allowed to be children of this class.
Note that this is intended for use with CMSMain and may not be respected with other model management methods.
bool
showingCMSTree()
Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?
string
CMSTreeClasses()
Return the CSS classes to apply to this node in the CMS tree.
DataObject&static>
stageChildren(bool $showAll = false, bool $skipParentIDFilter = false)
Return children in the stage site.
DataObject&static>
liveChildren(bool $showAll = false, bool $onlyDeletedFromStage = false)
Return children in the live site, if it exists.
DataObject&Hierarchy
getParent(string $filter = null)
Get this object's parent, optionally filtered by an SQL clause. If the clause doesn't match the parent, nothing is returned.
DataObject&static>
getAncestors(bool $includeSelf = false)
Return all the parents of this class in a set ordered from the closest to furtherest parent.
string
getBreadcrumbs(string $separator = ' » ')
Returns a human-readable, flattened representation of the path to the object, using its Title attribute.
string
getTreeTitle()
Get the title that will be used in TreeDropdownField and other tree structures.
string|null
getSortField()
Get the name of the dedicated sort field, if there is one.
bool
canAddChildren(Member|null $member = null)
Returns true if the current user can add children to this page.
Denies permission if any of the following conditions is true:
- the record is versioned and archived
- canAddChildren() on a extension returns false
- canEdit() is not granted
- allowed_children is not set to "none"
protected
extendCanAddChildren()
No description
protected
onFlushCache()
Flush all Hierarchy caches:
- Children (instance)
- NumChildren (instance)
protected bool|null
canCreate(Member|null $member, array $context)
Block creating children not allowed for the parent type
DataObject
Parent()
No description