Hierarchy
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
protected | SS_Object | $owner | The object this extension is applied to. |
from Extension |
protected | DataObject | $ownerBaseClass | The base class that this extension was applied to; $this->owner must be one of these |
from Extension |
public | $class | from Extension | ||
protected | $markedNodes | |||
protected | $markingFilter | |||
protected | int | $_cache_numChildren | ||
protected static | array | $marked | Cache of DataObjects' marked statuses: [ClassName][ID] = bool |
|
protected static | array | $expanded | Cache of DataObjects' expanded statuses: [ClassName][ID] = bool |
|
protected static | array | $treeOpened | Cache of DataObjects' opened statuses: [ClassName][ID] = bool |
Methods
Called when this extension is added to a particular class
Helper method to strip eval'ed arguments from a string thats passed to DataObject::$extensions or Object::add_extension().
Validate the owner object - check for existence of infinite loops.
Update the database schema as required by this extension.
Define extra database 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().
This function is used to provide modifications to the form used for front end forms. DataObject->getFrontEndFields()
This is used to provide modifications to the form actions used in the CMS. DataObject->getCMSActions().
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']
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']
Returns the children of this DataObject as an XHTML UL. This will be called recursively on each child, so if they have children they will be displayed as a UL inside a LI.
Mark a segment of the tree, by calling mark().
Filter the marking to only those object with $node->$parameterName == $parameterValue
Filter the marking to only those where the function returns true. The node in question will be passed to the function.
Returns true if the marking filter matches on the given node.
Mark all children of the given node that match the marking filter.
Ensure marked nodes that have children are also marked expanded. Call this after marking but before iterating over the tree.
Return CSS classes of 'unexpanded', 'closed', both, or neither, as well as a 'jstree-*' state depending on the marking of this DataObject.
Mark the children of the DataObject with the given ID.
Expose the given object in the tree, by marking this page and all it ancestors.
Return an array of this page and its ancestors, ordered item -> root.
Get a list of this DataObject's and all it's descendants ID, and put them in $idList.
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 augumented by augmentNumChildrenCountQuery().
Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?
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 lowest to highest parent.
Returns a human-readable, flattened representation of the path to the object, using its Title attribute.
Get the next node in the tree of the type. If there is no instance of the className descended from this node, then search the parents.
Get the next node in the tree of the type. If there is no instance of the className descended from this node, then search the parents.
Flush all Hierarchy caches:
- Children (instance)
- NumChildren (instance)
- Marked (global)
- Expanded (global)
- TreeOpened (global)
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(SS_Object $owner, string $ownerBaseClass = null)
Set the owner of this extension.
clearOwner()
No description
SS_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 thats passed to DataObject::$extensions or Object::add_extension().
static
get_extra_config($class, $extension, $args)
No description
static
unload_extra_statics($class, $extension)
No description
validate(ValidationResult $validationResult)
Validate the owner object - check for existence of infinite loops.
augmentSQL(SQLQuery $query)
Edit the given query object to support queries for this extension
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.
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($class = null, $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.
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.
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.
updateCMSActions(FieldList $actions)
This is used to provide modifications to the form actions used in the CMS. 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']
string
getChildrenAsUL(string $attributes = "", string|callable $titleEval = '"<li>" . $child->Title', string $extraArg = null, bool $limitToMarked = false, string $childrenMethod = "AllChildrenIncludingDeleted", $numChildrenMethod = "numChildren", bool $rootCall = true, int $nodeCountThreshold = null, callable $nodeCountCallback = null)
Returns the children of this DataObject as an XHTML UL. This will be called recursively on each child, so if they have children they will be displayed as a UL inside a LI.
int
markPartialTree(int $nodeCountThreshold = null, $context = null, $childrenMethod = "AllChildrenIncludingDeleted", $numChildrenMethod = "numChildren")
Mark a segment of the tree, by calling mark().
The method performs a breadth-first traversal until the number of nodes is more than minCount. This is used to get a limited number of tree nodes to show in the CMS initially.
This method returns the number of nodes marked. After this method is called other methods can check isExpanded()} and {@link isMarked() on individual nodes.
setMarkingFilter(string $parameterName, mixed $parameterValue)
Filter the marking to only those object with $node->$parameterName == $parameterValue
setMarkingFilterFunction(string $funcName)
Filter the marking to only those where the function returns true. The node in question will be passed to the function.
bool
markingFilterMatches(DataObject $node)
Returns true if the marking filter matches on the given node.
DataList
markChildren(DataObject $node, mixed $context = null, string $childrenMethod = "AllChildrenIncludingDeleted", string $numChildrenMethod = "numChildren")
Mark all children of the given node that match the marking filter.
protected
markingFinished(string $numChildrenMethod = "numChildren")
Ensure marked nodes that have children are also marked expanded. Call this after marking but before iterating over the tree.
string
markingClasses(string $numChildrenMethod = "numChildren")
Return CSS classes of 'unexpanded', 'closed', both, or neither, as well as a 'jstree-*' state depending on the marking of this DataObject.
bool
markById(int $id, bool $open = false)
Mark the children of the DataObject with the given ID.
markToExpose(DataObject $childObj)
Expose the given object in the tree, by marking this page and all it ancestors.
array
markedNodeIDs()
Return the IDs of all the marked nodes.
SiteTree[]
parentStack()
Return an array of this page and its ancestors, ordered item -> root.
markExpanded()
Mark this DataObject as expanded.
markUnexpanded()
Mark this DataObject as unexpanded.
markOpened()
Mark this DataObject's tree as opened.
markClosed()
Mark this DataObject's tree as closed.
bool
isMarked()
Check if this DataObject is marked.
bool
isExpanded()
Check if this DataObject is expanded.
bool
isTreeOpened()
Check if this DataObject's tree is opened.
int[]
getDescendantIDList()
Get a list of this DataObject's and all it's descendants IDs.
loadDescendantIDListInto(array $idList)
Get a list of this DataObject's and all it's descendants ID, and put them in $idList.
DataList
Children()
Get the children for this DataObject.
DataList
AllChildren()
Return all children, including those 'not in menus'.
ArrayList
AllChildrenIncludingDeleted(mixed $context = null)
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.
ArrayList
doAllChildrenIncludingDeleted(mixed $context = null)
No description
DataList
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 augmentNumChildrenCountQuery().
bool
showingCMSTree()
Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?
DataList
stageChildren(bool $showAll = false)
Return children in the stage site.
DataList
liveChildren(bool $showAll = false, bool $onlyDeletedFromStage = false)
Return children in the live site, if it exists.
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.
ArrayList
getAncestors()
Return all the parents of this class in a set ordered from the lowest to highest parent.
string
getBreadcrumbs(string $separator = ' » ')
Returns a human-readable, flattened representation of the path to the object, using its Title attribute.
DataObject
naturalPrev(string $className, DataObject $afterNode = null)
Get the next node in the tree of the type. If there is no instance of the className descended from this node, then search the parents.
DataObject
naturalNext(string $className = null, string|int $root = 0, DataObject $afterNode = null)
Get the next node in the tree of the type. If there is no instance of the className descended from this node, then search the parents.
flushCache()
Flush all Hierarchy caches:
- Children (instance)
- NumChildren (instance)
- Marked (global)
- Expanded (global)
- TreeOpened (global)
static
reset()
Reset global Hierarchy caches:
- Marked
- Expanded
- TreeOpened
DataObject
Parent()
No description