CRM_Core_Resources_CollectionTrait
Class CRM_Core_Resources_CollectionTrait
This is a building-block for creating classes which maintain a list of resources.
It implements of the CollectionInterface
.
Tags
Table of Contents
Properties
- $defaults : array<string|int, mixed>
- Static defaults - a list of options to apply to any new snippets.
- $isSorted : bool
- Whether the snippets array has been sorted
- $snippets : array<string|int, mixed>
- List of snippets to inject within region.
- $types : array<string|int, mixed>
- Whitelist of supported types.
Methods
- _cmpSnippet() : int
- add() : array<string|int, mixed>
- Add an item to the collection.
- addBundle() : static
- Assimilate all the resources listed in a bundle.
- clear() : static
- Remove all snippets.
- filter() : static
- Alter the contents of the collection.
- find() : iterable<string|int, mixed>
- Find all snippets which match the given criterion.
- findCreateSettingSnippet() : array<string|int, mixed>
- get() : array<string|int, mixed>|null
- Get snippet.
- getAll() : iterable<string|int, mixed>
- Get a list of all snippets in this collection.
- getSettings() : array<string|int, mixed>
- Get a fully-formed/altered list of settings, including the results of any callbacks/listeners.
- merge() : static
- Assimilate a list of resources into this list.
- update() : static
- Update specific properties of a snippet.
- nextId() : mixed
- resolveName() : mixed
- sort() : static
- Ensure that the collection is sorted.
Properties
$defaults
Static defaults - a list of options to apply to any new snippets.
protected
array<string|int, mixed>
$defaults
= ['weight' => 1, 'disabled' => \FALSE]
$isSorted
Whether the snippets array has been sorted
protected
bool
$isSorted
= \TRUE
$snippets
List of snippets to inject within region.
protected
array<string|int, mixed>
$snippets
= []
e.g. $this->_snippets[3]['type'] = 'template';
$types
Whitelist of supported types.
protected
array<string|int, mixed>
$types
= []
Methods
_cmpSnippet()
public
static _cmpSnippet(mixed $a, mixed $b) : int
Parameters
- $a : mixed
- $b : mixed
Return values
intadd()
Add an item to the collection.
public
add(array<string|int, mixed> $snippet) : array<string|int, mixed>
Parameters
- $snippet : array<string|int, mixed>
-
Resource options. See CollectionInterface docs.
Tags
Return values
array<string|int, mixed> —The full/computed snippet (with defaults applied).
addBundle()
Assimilate all the resources listed in a bundle.
public
addBundle(iterable<string|int, mixed>|string|CRM_Core_Resources_Bundle $bundle) : static
Parameters
- $bundle : iterable<string|int, mixed>|string|CRM_Core_Resources_Bundle
-
Either bundle object, or the symbolic name of a bundle. Note: For symbolic names, the bundle must be a container service ('bundle.FOO').
Return values
staticclear()
Remove all snippets.
public
clear() : static
Tags
Return values
staticfilter()
Alter the contents of the collection.
public
filter(callable $callback) : static
Parameters
- $callback : callable
-
The callback is invoked once for each member in the collection. The callback may return one of three values:
- TRUE: The item is OK and belongs in the collection.
- FALSE: The item is not OK and should be omitted from the collection.
- Array: The item should be revised (using the returned value).
Tags
Return values
staticfind()
Find all snippets which match the given criterion.
public
find(callable $callback) : iterable<string|int, mixed>
Parameters
- $callback : callable
-
The callback is invoked once for each member in the collection. The callback may return one of three values:
- TRUE: The item is OK and belongs in the collection.
- FALSE: The item is not OK and should be omitted from the collection.
Tags
Return values
iterable<string|int, mixed> —List of matching snippets.
findCreateSettingSnippet()
public
& findCreateSettingSnippet([mixed $options = [] ]) : array<string|int, mixed>
Parameters
- $options : mixed = []
Return values
array<string|int, mixed>get()
Get snippet.
public
& get(string $name) : array<string|int, mixed>|null
Parameters
- $name : string
Tags
Return values
array<string|int, mixed>|nullgetAll()
Get a list of all snippets in this collection.
public
getAll() : iterable<string|int, mixed>
Tags
Return values
iterable<string|int, mixed>getSettings()
Get a fully-formed/altered list of settings, including the results of any callbacks/listeners.
public
getSettings() : array<string|int, mixed>
Return values
array<string|int, mixed>merge()
Assimilate a list of resources into this list.
public
merge(iterable<string|int, mixed> $snippets) : static
Parameters
- $snippets : iterable<string|int, mixed>
-
List of snippets to add.
Tags
Return values
staticupdate()
Update specific properties of a snippet.
public
update(string $name, array<string|int, mixed> $snippet) : static
Parameters
- $name : string
-
Symbolic of the resource/snippet to update.
- $snippet : array<string|int, mixed>
-
Resource options. See CollectionInterface docs.
Tags
Return values
staticnextId()
protected
nextId() : mixed
resolveName()
protected
resolveName(string $name) : mixed
Parameters
- $name : string
-
Name or alias. return array List of real names.
sort()
Ensure that the collection is sorted.
protected
sort() : static