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
protected static array $cache_numChildren

A cache used by numChildren().

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
object
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 static 
unload_extra_statics($class, $extension) deprecated

No description

public
validate(ValidationResult $validationResult)

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

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

Edit the given query object to support queries for this extension

public
augmentDatabase()

Update the database schema as required by this extension.

public
augmentWrite(array $manipulation)

Augment a write-record request.

public
onBeforeWrite()

Extend the owner's onBeforeWrite() logic

public
onAfterWrite()

Extend the owner's onAfterWrite() logic

public
onBeforeDelete()

Extend the owner's onBeforeDelete() logic

public
onAfterDelete()

Extend the owner's onAfterDelete() logic

public
requireDefaultRecords()

Extend the owner's requireDefaultRecords() logic

public
populateDefaults()

Extend the owner's populateDefaults() logic

public
onAfterBuild()

Extend the owner's onAfterBuild() logic

public
bool|null
can(Member $member)

Influence the owner's can() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

public
bool|null
canEdit(Member $member)

Influence the owner's canEdit() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

public
bool|null
canDelete(Member $member)

Influence the owner's canDelete() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

public
bool|null
canCreate(Member $member)

Influence the owner's canCreate() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

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

Define extra database fields

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

public
void
updateCMSCompositeValidator(CompositeValidator $compositeValidator)

This function is used to provide modifications to the Validators used on a DataObject.

public
updateFrontEndFields(FieldList $fields)

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

public
updateCMSActions(FieldList $actions)

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

public
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']

public
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']

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

No description

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

Get the children for this DataObject filtered by canView()

public
AllChildren()

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

public
AllChildrenIncludingDeleted()

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

public
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
bool
showingCMSTree()

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

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

Return children in the stage site.

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

Flush all Hierarchy caches:

  • Children (instance)
  • NumChildren (instance)

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

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 DataObject::$extensions or Object::add_extension().

Parameters

string $extensionStr

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

Return Value

string

Extension classname, e.g. "Versioned"

static unload_extra_statics($class, $extension) deprecated

deprecated 4.7.0 Will be removed without equivalent functionality

No description

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 Versioned->augmentDatabase for an example.

augmentWrite(array $manipulation)

Augment a write-record request.

Parameters

array $manipulation

Array of operations to augment.

onBeforeWrite()

Extend the owner's onBeforeWrite() logic

See DataObject::onBeforeWrite() for context.

onAfterWrite()

Extend the owner's onAfterWrite() logic

See DataObject::onAfterWrite() for context.

onBeforeDelete()

Extend the owner's onBeforeDelete() logic

See DataObject::onBeforeDelete() for context.

onAfterDelete()

Extend the owner's onAfterDelete() logic

See DataObject::onAfterDelete() for context.

requireDefaultRecords()

Extend the owner's requireDefaultRecords() logic

See DataObject::requireDefaultRecords() for context.

populateDefaults()

Extend the owner's populateDefaults() logic

See DataObject::populateDefaults() for context.

onAfterBuild()

Extend the owner's onAfterBuild() logic

See DataObject::onAfterBuild() for context.

bool|null can(Member $member)

Influence the owner's can() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

See DataObject::can()} and {@link DataObject::extendedCan() for context.

Parameters

Member $member

Return Value

bool|null

bool|null canEdit(Member $member)

Influence the owner's canEdit() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

See DataObject::canEdit()} and {@link DataObject::extendedCan() for context.

Parameters

Member $member

Return Value

bool|null

bool|null canDelete(Member $member)

Influence the owner's canDelete() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

See DataObject::canDelete()} and {@link DataObject::extendedCan() for context.

Parameters

Member $member

Return Value

bool|null

bool|null canCreate(Member $member)

Influence the owner's canCreate() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

See DataObject::canCreate()} and {@link DataObject::extendedCan() for context.

Parameters

Member $member

Return Value

bool|null

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

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

Caution: Use FieldList->addFieldToTab() to add fields.

Parameters

FieldList $fields

FieldList with a contained TabSet

void updateCMSCompositeValidator(CompositeValidator $compositeValidator)

This function is used to provide modifications to the Validators used on a DataObject.

Caution: Use CompositeValidator->addValidator() to add Validators.

Parameters

CompositeValidator $compositeValidator

Return Value

void

updateFrontEndFields(FieldList $fields)

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

Caution: Use 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. 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)

No description

Parameters

$class
$extension
$args

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

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

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

bool $skipParentIDFilter

Set to true to suppress 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 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 Title attribute.

Parameters

string $separator

Return Value

string

flushCache()

Flush all Hierarchy caches:

  • Children (instance)
  • NumChildren (instance)

DataObject Parent()

No description

Return Value

DataObject