3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class CRM_Core_Resources_Bundle
15 * A bundle is a collection of web resources with the following details:
16 * - Only scripts, styles, and settings are allowed. Free-form markup is not.
17 * - Resources *may* have a 'region'. Hopefully, this is not necessary for most bundles.
18 * - If no 'region' is given, then CRM_Core_Resources will pick a default at activation time.
20 class CRM_Core_Resources_Bundle
implements CRM_Core_Resources_CollectionInterface
{
22 use CRM_Core_Resources_CollectionTrait
;
25 * Symbolic name for this bundle.
32 * @param string|NULL $name
33 * @param string[]|NULL $types
34 * List of resource-types to permit in this bundle. NULL for a default list.
35 * Ex: ['styleFile', 'styleUrl']
36 * The following aliases are allowed: '*all*', '*default*', '*script*', '*style*'
38 public function __construct($name = NULL, $types = NULL) {
42 '*all*' => ['script', 'scriptFile', 'scriptUrl', 'settings', 'style', 'styleFile', 'styleUrl', 'markup', 'template', 'callback'],
43 '*default*' => ['script', 'scriptFile', 'scriptUrl', 'settings', 'style', 'styleFile', 'styleUrl'],
44 '*style*' => ['style', 'styleFile', 'styleUrl'],
45 '*script*' => ['script', 'scriptFile', 'scriptUrl'],
47 $mapType = function ($t) use ($typeAliases) {
48 return $typeAliases[$t] ??
[$t];
50 $types = $types ?
: ['*default*'];
51 $this->types
= array_unique(array_merge(...array_map($mapType, (array) $types)));
55 * Fill in default values for the 'region' property.
59 public function fillDefaults() {
60 $this->filter(function ($s) {
61 if (!isset($s['region'])) {
62 if ($s['type'] === 'settings') {
65 elseif (preg_match(';^(markup|template|callback);', $s['type'])) {
66 $s['region'] = 'page-header';
69 $s['region'] = CRM_Core_Resources_Common
::REGION
;