CRM_Core_Resources_Bundle
in package
implements
CRM_Core_Resources_CollectionInterface
uses
CRM_Core_Resources_CollectionTrait
Class CRM_Core_Resources_Bundle
A bundle is a collection of web resources with the following details:
- Only scripts, styles, and settings are allowed. Free-form markup is not.
- Resources may have a 'region'. Hopefully, this is not necessary for most bundles.
- If no 'region' is given, then CRM_Core_Resources will pick a default at activation time.
Table of Contents
Interfaces
- CRM_Core_Resources_CollectionInterface
- Class CRM_Core_Resources_CollectionInterface
Properties
- $name : string|null
- Symbolic name for this bundle.
- $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
- __construct() : mixed
- _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.
- fillDefaults() : static
- Fill in default values for the 'region' property.
- 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
$name
Symbolic name for this bundle.
public
string|null
$name
$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
__construct()
public
__construct([string|null $name = NULL ][, array<string|int, string>|null $types = NULL ]) : mixed
Parameters
- $name : string|null = NULL
- $types : array<string|int, string>|null = NULL
-
List of resource-types to permit in this bundle. NULL for a default list. Ex: ['styleFile', 'styleUrl'] The following aliases are allowed: 'all', 'default', 'script', 'style'
_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
staticfillDefaults()
Fill in default values for the 'region' property.
public
fillDefaults() : static
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