Merge pull request #22555 from eileenmcnaughton/stricter
[civicrm-core.git] / CRM / Core / Region.php
index 3f4e1f29d04b2bfc328cf9734d9bda94b45d01d5..4d9f733068c67003c28ad68cd6345be2b37c3d3e 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * Maintain a set of markup/templates to inject inside various regions
  */
-class CRM_Core_Region {
+class CRM_Core_Region implements CRM_Core_Resources_CollectionInterface, CRM_Core_Resources_CollectionAdderInterface {
 
   /**
    * Obtain the content for a given region.
@@ -20,9 +20,7 @@ class CRM_Core_Region {
     return Civi::$statics[__CLASS__][$name];
   }
 
-  use CRM_Core_Resources_CollectionTrait {
-    CRM_Core_Resources_CollectionTrait::add as _add;
-  }
+  use CRM_Core_Resources_CollectionTrait;
 
   /**
    * Symbolic name of this region
@@ -36,7 +34,7 @@ class CRM_Core_Region {
    */
   public function __construct($name) {
     $this->_name = $name;
-    $this->types = ['markup', 'template', 'callback', 'scriptUrl', 'script', 'jquery', 'settings', 'style', 'styleUrl'];
+    $this->types = ['markup', 'template', 'callback', 'scriptFile', 'scriptUrl', 'script', 'jquery', 'settings', 'style', 'styleFile', 'styleUrl'];
     $this->defaults['region'] = $name;
 
     // Placeholder which represents any of the default content generated by the main Smarty template
@@ -63,6 +61,8 @@ class CRM_Core_Region {
       $this->snippets['default']['markup'] = $default;
     }
 
+    Civi::dispatcher()->dispatch('civi.region.render', \Civi\Core\Event\GenericHookEvent::create(['region' => $this]));
+
     $this->sort();
 
     $cms = CRM_Core_Config::singleton()->userSystem;
@@ -100,12 +100,24 @@ class CRM_Core_Region {
           ]);
           break;
 
+        case 'scriptFile':
+          foreach ($snippet['scriptFileUrls'] as $url) {
+            $html .= $renderSnippet(['type' => 'scriptUrl', 'scriptUrl' => $url] + $snippet);
+          }
+          break;
+
         case 'script':
           if (!$allowCmsOverride || !$cms->addScript($snippet['script'], $this->_name)) {
             $html .= sprintf("<script type=\"text/javascript\">\n%s\n</script>\n", $snippet['script']);
           }
           break;
 
+        case 'styleFile':
+          foreach ($snippet['styleFileUrls'] as $url) {
+            $html .= $renderSnippet(['type' => 'styleUrl', 'styleUrl' => $url] + $snippet);
+          }
+          break;
+
         case 'styleUrl':
           if (!$allowCmsOverride || !$cms->addStyleUrl($snippet['styleUrl'], $this->_name)) {
             $html .= sprintf("<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\"/>\n", $snippet['styleUrl']);