Skip to content

Commit

Permalink
Allow extensions to add core resources to the list
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Oct 30, 2018
1 parent 67f14d4 commit 7b8b530
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions CRM/Core/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,21 @@ public function addCoreResources($region = 'html-header') {
if (is_array($item)) {
$this->addSetting($item);
}
elseif (substr($item, -2) == 'js') {
// Don't bother looking for ts() calls in packages, there aren't any
$translate = (substr($item, 0, 3) == 'js/');
$this->addScriptFile('civicrm', $item, $jsWeight++, $region, $translate);
}
else {
$this->addStyleFile('civicrm', $item, -100, $region);
$ext = 'civicrm';
// Parse extension name in square brackets e.g. '[org.civicrm.api4]/js/api4.js'
if ($item[0] === '[') {
list($ext, $item) = explode(']', substr($item, 1));
}
$item = trim($item, '/\\');
if (substr($item, -2) == 'js') {
// Don't bother looking for ts() calls in packages, there aren't any
$translate = ($ext != 'civicrm' || substr($item, 0, 8) == 'packages' || substr($item, 0, 5) == 'bower');
$this->addScriptFile($ext, $item, $jsWeight++, $region, $translate);
}
else {
$this->addStyleFile($ext, $item, -100, $region);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,8 @@ public static function batchItems(&$results, &$items) {
/**
* This hook is called when core resources are being loaded
*
* For adding resources from an extension, place the extension name in square brackets like '[org.civicrm.api4]/js/api4.js'
*
* @see CRM_Core_Resources::coreResourceList
*
* @param array $list
Expand Down

0 comments on commit 7b8b530

Please sign in to comment.