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

public
__construct()

No description

public static 
add_to_class(string $class, string $extensionClass, mixed $args = null)

Called when this extension is added to a particular class

public
setOwner(object $owner)

Set the owner of this extension.

public
mixed
withOwner(mixed $owner, callable $callback, array $args = [])

Temporarily modify the owner. The original owner is ensured to be restored

public
clearOwner()

Clear the current owner, and restore extension to the state prior to the last setOwner()

public
T
getOwner()

Returns the owner of this extension.

public 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().

public
mixed
invokeExtension(object $owner, string $method, array ...$arguments)

Invoke extension point. This will prefer explicit extend prefixed methods.

public static 
get_extra_config($class, $extension, $args)

No description

protected
updateValidate(ValidationResult $validationResult)

Validate the owner object - check for existence of infinite loops.

public
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.

public
duplicateWithChildren()

Duplicates each child of this record recursively and returns the top-level duplicate record.

public
DataObject|static>
Children()

Get the children for this DataObject filtered by canView()

public
DataObject|static>
AllChildren()

Return all children, including those 'not in menus'.

public
DataObject|static>
AllChildrenIncludingDeleted()

Return all children, including those that have been deleted but are still in live.

public
DataObject|static>
AllHistoricalChildren()

Return all the children that this page had, including pages that were deleted from both stage & live.

public
int
numHistoricalChildren()

Return the number of children that this page ever had, including pages that were deleted.

public
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().

public
prepopulateTreeDataCache(DataList|array $recordList = null, array $options = [])

Pre-populate any appropriate caches prior to rendering a tree.

public 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.

public
string|null
defaultChild()

Returns the class name of the default class for children of this page.

public
string|null
defaultParent()

Returns the class name of the default class for the parent of this page.

public
array
allowedChildren()

Returns an array of the class names of classes that are allowed to be children of this class.

public
bool
showingCMSTree()

Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?

public
string
CMSTreeClasses()

Return the CSS classes to apply to this node in the CMS tree.

public
DataObject|static>
stageChildren(bool $showAll = false, bool $skipParentIDFilter = false)

Return children in the stage site.

public
DataObject|static>
liveChildren(bool $showAll = false, bool $onlyDeletedFromStage = false)

Return children in the live site, if it exists.

public
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.

public
DataObject|static>
getAncestors(bool $includeSelf = false)

Return all the parents of this class in a set ordered from the closest to furtherest parent.

public
string
getBreadcrumbs(string $separator = ' » ')

Returns a human-readable, flattened representation of the path to the object, using its Title attribute.

public
string
getTreeTitle()

Get the title that will be used in TreeDropdownField and other tree structures.

public
string|null
getSortField()

Get the name of the dedicated sort field, if there is one.

public
bool
canAddChildren(Member|null $member = null)

Returns true if the current user can add children to this page.

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

Parent()

No description

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

Parameters

string $class
string $extensionClass
mixed $args

setOwner(object $owner)

Set the owner of this extension.

Parameters

object $owner

The owner object

mixed withOwner(mixed $owner, callable $callback, array $args = [])

Temporarily modify the owner. The original owner is ensured to be restored

Parameters

mixed $owner

Owner to set

callable $callback

Callback to invoke

array $args

Args to pass to callback

Return Value

mixed

clearOwner()

Clear the current owner, and restore extension to the state prior to the last setOwner()

T getOwner()

Returns the owner of this extension.

Return Value

T

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().

Parameters

string $extensionStr

E.g. "Versioned('Stage','Live')"

Return Value

string

Extension classname, e.g. "Versioned"

mixed invokeExtension(object $owner, string $method, array ...$arguments)

Invoke extension point. This will prefer explicit extend prefixed methods.

Parameters

object $owner
string $method
array ...$arguments

Return Value

mixed

static get_extra_config($class, $extension, $args)

No description

Parameters

$class
$extension
$args

protected updateValidate(ValidationResult $validationResult)

Validate the owner object - check for existence of infinite loops.

Parameters

ValidationResult $validationResult

int[] getDescendantIDList()

Get a list of this DataObject's and all it's descendants IDs.

Return Value

int[]

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.

Parameters

array $idList

Array to put results in.

DataObject|Hierarchy $node

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.

Return Value

DataObject

DataObject&static> Children()

Get the children for this DataObject filtered by canView()

Return Value

DataObject&static>

DataObject&static> AllChildren()

Return all children, including those 'not in menus'.

Return Value

DataObject&static>

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.

Return Value

DataObject&static>

DataObject&static> AllHistoricalChildren()

Return all the children that this page had, including pages that were deleted from both stage & live.

Return Value

DataObject&static>

Exceptions

Exception

int numHistoricalChildren()

Return the number of children that this page ever had, including pages that were deleted.

Return Value

int

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().

Parameters

bool $cache

Whether to retrieve values from cache

Return Value

int

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.

Parameters

DataList|array $recordList

The list of records to prepopulate caches for. Null for all records.

array $options

A map of hints about what should be cached. "numChildrenMethod" and "childrenMethod" are allowed keys.

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.

Parameters

string $baseClass
array $idList

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.

Return Value

string|null

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.

Return Value

string|null

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.

Return Value

array

bool showingCMSTree()

Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?

Return Value

bool

string CMSTreeClasses()

Return the CSS classes to apply to this node in the CMS tree.

Return Value

string

DataObject&static> stageChildren(bool $showAll = false, bool $skipParentIDFilter = false)

Return children in the stage site.

Parameters

bool $showAll

Include all of the elements, even those not shown in the menus. Only applicable when extension is applied to SiteTree.

bool $skipParentIDFilter

Set to true to suppress the ParentID and ID where statements.

Return Value

DataObject&static>

DataObject&static> liveChildren(bool $showAll = false, bool $onlyDeletedFromStage = false)

Return children in the live site, if it exists.

Parameters

bool $showAll

Include all of the elements, even those not shown in the menus. Only applicable when extension is applied to SiteTree.

bool $onlyDeletedFromStage

Only return items that have been deleted from stage

Return Value

DataObject&static>

Exceptions

Exception

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.

Parameters

string $filter

Return Value

DataObject&Hierarchy

DataObject&static> getAncestors(bool $includeSelf = false)

Return all the parents of this class in a set ordered from the closest to furtherest parent.

Parameters

bool $includeSelf

Return Value

DataObject&static>

string getBreadcrumbs(string $separator = ' » ')

Returns a human-readable, flattened representation of the path to the object, using its Title attribute.

Parameters

string $separator

Return Value

string

string getTreeTitle()

Get the title that will be used in TreeDropdownField and other tree structures.

Return Value

string

string|null getSortField()

Get the name of the dedicated sort field, if there is one.

Return Value

string|null

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"

Parameters

Member|null $member

Return Value

bool

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

Parameters

Member|null $member
array $context

Return Value

bool|null

DataObject Parent()

No description

Return Value

DataObject