class Hierarchy extends DataExtension (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

DataObject|Hierarchy $owner
static private int $node_threshold_total

The lower bounds for the amount of nodes to mark. If set, the logic will expand nodes until it reaches at least this number, and then stops. Root nodes will always show regardless of this settting. Further nodes can be lazy-loaded via ajax. This isn't a hard limit. Example: On a value of 10, with 20 root nodes, each having 30 children, the actual node count will be 50 (all root nodes plus first expanded child).

static private int $node_threshold_leaf

Limit on the maximum children a specific node can display. Serves as a hard limit to avoid exceeding available server resources in generating the tree, and browser resources in rendering it. Nodes with children exceeding this value typically won't display any children, although this is configurable through the $nodeCountCallback parameter in {@link getChildrenAsUL()}. "Root" nodes will always show all children, regardless of this setting.

static private array $hide_from_hierarchy

A list of classnames to exclude from display in both the CMS and front end displays. ->Children() and ->AllChildren affected.

static private array $hide_from_cms_tree

A list of classnames to exclude from display in the page tree views of the CMS, unlike $hide_from_hierarchy above which effects both CMS and front end.

static private bool $prepopulate_numchildren_cache

Used to enable or disable the prepopulation of the numchildren cache.

static private array $non_virtual_fields

Prevent virtual page virtualising these fields

int $ParentID

Methods

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

object
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 {@link DataObject::$extensions} or {@link Object::add_extension()}.

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

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

static 
unload_extra_statics($class, $extension)

No description

validate(ValidationResult $validationResult)

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

augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)

Edit the given query object to support queries for this extension

augmentDatabase()

Update the database schema as required by this extension.

augmentWrite(array $manipulation)

Augment a write-record request.

onBeforeWrite()

No description

onAfterWrite()

No description

onBeforeDelete()

No description

onAfterDelete()

No description

requireDefaultRecords()

No description

populateDefaults()

No description

can($member)

No description

canEdit($member)

No description

canDelete($member)

No description

canCreate($member)

No description

array
extraStatics(string $class = null, string $extension = null)

Define extra database fields

updateCMSFields(FieldList $fields)

This function is used to provide modifications to the form in the CMS by the extension. By default, no changes are made. {@link DataObject->getCMSFields()}.

updateFrontEndFields(FieldList $fields)

This function is used to provide modifications to the form used for front end forms. {@link DataObject->getFrontEndFields()}

updateCMSActions(FieldList $actions)

This is used to provide modifications to the form actions used in the CMS. {@link DataObject->getCMSActions()}.

updateSummaryFields(array $fields)

this function is used to provide modifications to the summary fields in CMS by the extension By default, the summaryField() of its owner will merge more fields defined in the extension's $extra_fields['summary_fields']

updateFieldLabels(array $labels)

this function is used to provide modifications to the fields labels in CMS by the extension By default, the fieldLabels() of its owner will merge more fields defined in the extension's $extra_fields['field_labels']

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

No description

int[]
getDescendantIDList()

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

Children()

Get the children for this DataObject filtered by canView()

AllChildren()

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

AllChildrenIncludingDeleted()

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

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 augumented by {@link augmentNumChildrenCountQuery()}.

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

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

static 
prepopulate_numchildren_cache($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.

bool
showingCMSTree()

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

stageChildren(bool $showAll = false, bool $skipParentIDFilter = false)

Return children in the stage site.

liveChildren(bool $showAll = false, bool $onlyDeletedFromStage = false)

Return children in the live site, if it exists.

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.

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 {@link Title} attribute.

flushCache()

Flush all Hierarchy caches:

  • Children (instance)
  • NumChildren (instance)

Parent()

No description

Details

__construct()

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

object getOwner()

Returns the owner of this extension.

Return Value

object

static string get_classname_without_arguments(string $extensionStr)

Helper method to strip eval'ed arguments from a string that's passed to {@link DataObject::$extensions} or {@link 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 unload_extra_statics($class, $extension)

Parameters

$class
$extension

validate(ValidationResult $validationResult)

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

Parameters

ValidationResult $validationResult

Local validation result

augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)

Edit the given query object to support queries for this extension

Parameters

SQLSelect $query

Query to augment.

DataQuery $dataQuery

Container DataQuery for this SQLSelect

augmentDatabase()

Update the database schema as required by this extension.

When duplicating a table's structure, remember to duplicate the create options as well. See {@link Versioned->augmentDatabase} for an example.

augmentWrite(array $manipulation)

Augment a write-record request.

Parameters

array $manipulation

Array of operations to augment.

onBeforeWrite()

onAfterWrite()

onBeforeDelete()

onAfterDelete()

requireDefaultRecords()

populateDefaults()

can($member)

Parameters

$member

canEdit($member)

Parameters

$member

canDelete($member)

Parameters

$member

canCreate($member)

Parameters

$member

array extraStatics(string $class = null, string $extension = null)

Define extra database fields

Return a map where the keys are db, has_one, etc, and the values are additional fields/relations to be defined.

Parameters

string $class

since this method might be called on the class directly

string $extension

since this can help to extract parameters to help set indexes

Return Value

array

Returns a map where the keys are db, has_one, etc, and the values are additional fields/relations to be defined.

updateCMSFields(FieldList $fields)

This function is used to provide modifications to the form in the CMS by the extension. By default, no changes are made. {@link DataObject->getCMSFields()}.

Please consider using {@link updateFormFields()} to globally add formfields to the record. The method {@link updateCMSFields()} should just be used to add or modify tabs, or fields which are specific to the CMS-context.

Caution: Use {@link FieldList->addFieldToTab()} to add fields.

Parameters

FieldList $fields

FieldList with a contained TabSet

updateFrontEndFields(FieldList $fields)

This function is used to provide modifications to the form used for front end forms. {@link DataObject->getFrontEndFields()}

Caution: Use {@link FieldList->push()} to add fields.

Parameters

FieldList $fields

FieldList without TabSet nesting

updateCMSActions(FieldList $actions)

This is used to provide modifications to the form actions used in the CMS. {@link DataObject->getCMSActions()}.

Parameters

FieldList $actions

FieldList

updateSummaryFields(array $fields)

this function is used to provide modifications to the summary fields in CMS by the extension By default, the summaryField() of its owner will merge more fields defined in the extension's $extra_fields['summary_fields']

Parameters

array $fields

Array of field names

updateFieldLabels(array $labels)

this function is used to provide modifications to the fields labels in CMS by the extension By default, the fieldLabels() of its owner will merge more fields defined in the extension's $extra_fields['field_labels']

Parameters

array $labels

Array of field labels

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

Parameters

$class
$extension
$args

int[] getDescendantIDList()

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

Return Value

int[]

SS_List Children()

Get the children for this DataObject filtered by canView()

Return Value

SS_List

DataList AllChildren()

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

Return Value

DataList

ArrayList 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

ArrayList

DataList AllHistoricalChildren()

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

Return Value

DataList

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 augumented by {@link 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 cace 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($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

$baseClass
array $idList

bool showingCMSTree()

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

Return Value

bool

DataList 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 {@link SiteTree}.

bool $skipParentIDFilter

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

Return Value

DataList

DataList 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 {@link SiteTree}.

bool $onlyDeletedFromStage

Only return items that have been deleted from stage

Return Value

DataList

Exceptions

Exception

DataObject 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

ArrayList 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

ArrayList

string getBreadcrumbs(string $separator = ' » ')

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

Parameters

string $separator

Return Value

string

flushCache()

Flush all Hierarchy caches:

  • Children (instance)
  • NumChildren (instance)

DataObject Parent()

Return Value

DataObject