class MarkedSet (View source)

Contains a set of hierarchical objects generated from a marking compilation run.

A set of nodes can be "marked" for later export, in order to prevent having to export the entire contents of a potentially huge tree.

Traits

A class that can be instantiated or replaced via DI

Properties

array $markingFilter

Optional filter callback for filtering nodes to mark

Methods

static Injectable
create(array ...$args)

An implementation of the factory method, allows you to create an instance of a class

static Injectable
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

__construct(DataObject $rootNode, string $childrenMethod = null, string $numChildrenMethod = null, int $nodeCountThreshold = null, int $maxChildNodes = null)

Create an empty set with the given class

int
getNodeCountThreshold()

Get total number of nodes to get. This acts as a soft lower-bounds for number of nodes to search until found.

int
getMaxChildNodes()

Max number of nodes that can be physically rendered at any level.

$this
setMaxChildNodes(int $count)

Set hard limit of number of nodes to get for this level

$this
setNodeCountThreshold(int $total)

Set max node count

string
getChildrenMethod()

Get method to use for getting children

$this
setChildrenMethod(string $method)

Set method to use for getting children

string
getNumChildrenMethod()

Get method name for num children

$this
setNumChildrenMethod(string $method)

Set method name to get num children

string
renderChildren(string $template = null, array|callable $context = [])

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.

array
getChildrenAsArray(callable $serialiseEval = null)

Get child data formatted as JSON

$this
markPartialTree()

Mark a segment of the tree, by calling mark().

$this
setMarkingFilter(string $parameterName, mixed $parameterValue)

Filter the marking to only those object with $node->$parameterName == $parameterValue

$this
setMarkingFilterFunction(callable $callback)

Filter the marking to only those where the function returns true. The node in question will be passed to the function.

bool
markById(int $id, bool $open = false)

Mark the children of the DataObject with the given ID.

$this
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.

clearMarks()

Reset marked nodes

$this
markExpanded(DataObject $node)

Mark this DataObject as expanded.

$this
markUnexpanded(DataObject $node)

Mark this DataObject as unexpanded.

$this
markOpened(DataObject $node)

Mark this DataObject's tree as opened.

$this
markClosed(DataObject $node)

Mark this DataObject's tree as closed.

bool
isMarked(DataObject $node)

Check if this DataObject is marked.

bool
isExpanded(DataObject $node)

Check if this DataObject is expanded.

bool
isTreeOpened(DataObject $node)

Check if this DataObject's tree is opened.

$this
setLimitingEnabled(bool $enabled)

Toggle limiting on or off

bool
getLimitingEnabled()

Check if limiting is enabled

Details

static Injectable create(array ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create('SiteTree'); $list = SiteTree::get();

Parameters

array ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

__construct(DataObject $rootNode, string $childrenMethod = null, string $numChildrenMethod = null, int $nodeCountThreshold = null, int $maxChildNodes = null)

Create an empty set with the given class

Parameters

DataObject $rootNode

Root node for this set. To collect the entire tree, pass in a singelton object.

string $childrenMethod

Override children method

string $numChildrenMethod

Override children counting method

int $nodeCountThreshold

Minimum threshold for number nodes to mark

int $maxChildNodes

Maximum threshold for number of child nodes to include

int getNodeCountThreshold()

Get total number of nodes to get. This acts as a soft lower-bounds for number of nodes to search until found.

Defaults to value of node_threshold_total of hierarchy class.

Return Value

int

int getMaxChildNodes()

Max number of nodes that can be physically rendered at any level.

Acts as a hard upper bound, after which nodes will be trimmed for performance reasons.

Return Value

int

$this setMaxChildNodes(int $count)

Set hard limit of number of nodes to get for this level

Parameters

int $count

Return Value

$this

$this setNodeCountThreshold(int $total)

Set max node count

Parameters

int $total

Return Value

$this

string getChildrenMethod()

Get method to use for getting children

Return Value

string

$this setChildrenMethod(string $method)

Set method to use for getting children

Parameters

string $method

Return Value

$this

Exceptions

InvalidArgumentException

string getNumChildrenMethod()

Get method name for num children

Return Value

string

$this setNumChildrenMethod(string $method)

Set method name to get num children

Parameters

string $method

Return Value

$this

string renderChildren(string $template = null, array|callable $context = [])

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.

Parameters

string $template

Template for items in the list

array|callable $context

Additional arguments to add to template when rendering due to excessive line length. If callable, this will be executed with the current node dataobject

Return Value

string

array getChildrenAsArray(callable $serialiseEval = null)

Get child data formatted as JSON

Parameters

callable $serialiseEval

A callback that takes a DataObject as a single parameter, and should return an array containing a simple array representation. This result will replace the 'node' property at each point in the tree.

Return Value

array

$this markPartialTree()

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 {@link isExpanded()} and {@link isMarked()} on individual nodes.

Return Value

$this

$this setMarkingFilter(string $parameterName, mixed $parameterValue)

Filter the marking to only those object with $node->$parameterName == $parameterValue

Parameters

string $parameterName

The parameter on each node to check when marking.

mixed $parameterValue

The value the parameter must be to be marked.

Return Value

$this

$this setMarkingFilterFunction(callable $callback)

Filter the marking to only those where the function returns true. The node in question will be passed to the function.

Parameters

callable $callback

Callback to filter

Return Value

$this

bool markById(int $id, bool $open = false)

Mark the children of the DataObject with the given ID.

Parameters

int $id

ID of parent node

bool $open

If this is true, mark the parent node as opened

Return Value

bool

$this markToExpose(DataObject $childObj)

Expose the given object in the tree, by marking this page and all it ancestors.

Parameters

DataObject $childObj

Return Value

$this

array markedNodeIDs()

Return the IDs of all the marked nodes.

Return Value

array

clearMarks()

Reset marked nodes

$this markExpanded(DataObject $node)

Mark this DataObject as expanded.

Parameters

DataObject $node

Return Value

$this

$this markUnexpanded(DataObject $node)

Mark this DataObject as unexpanded.

Parameters

DataObject $node

Return Value

$this

$this markOpened(DataObject $node)

Mark this DataObject's tree as opened.

Parameters

DataObject $node

Return Value

$this

$this markClosed(DataObject $node)

Mark this DataObject's tree as closed.

Parameters

DataObject $node

Return Value

$this

bool isMarked(DataObject $node)

Check if this DataObject is marked.

Parameters

DataObject $node

Return Value

bool

bool isExpanded(DataObject $node)

Check if this DataObject is expanded.

An expanded object has had it's children iterated through.

Parameters

DataObject $node

Return Value

bool

bool isTreeOpened(DataObject $node)

Check if this DataObject's tree is opened.

This is an expanded node which also should have children visually shown.

Parameters

DataObject $node

Return Value

bool

$this setLimitingEnabled(bool $enabled)

Toggle limiting on or off

Parameters

bool $enabled

Return Value

$this

bool getLimitingEnabled()

Check if limiting is enabled

Return Value

bool