CRM_Core_Resources::addCoreResources - Option `$region` is not meaningfully used
authorTim Otten <totten@civicrm.org>
Tue, 18 Aug 2020 05:05:02 +0000 (22:05 -0700)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 3 Sep 2020 22:02:17 +0000 (08:02 +1000)
If you grep universe for `addCoreResources` and `addCoreStyles`, all matches
fall into these buckets:

1. They use the implicit default region.
2. They explicitly use the `html-header` region.
3. (Singular case) addCoreResources($region) delegates to addCoreStyles($region);
   but given 1+2, this must still be `html-header`.

CRM/Core/Resources.php

index 4265fee1cf14ec548f6d13c6ec34759819de193c..3ac2b72e882e17f3f6a5c4a9b9d467470cc69e1e 100644 (file)
@@ -564,6 +564,13 @@ class CRM_Core_Resources {
    * @return CRM_Core_Resources
    */
   public function addCoreResources($region = 'html-header') {
+    if ($region !== 'html-header') {
+      // The signature of this method allowed different regions. However, this
+      // doesn't appear to be used - based on grepping `universe` generally
+      // and `civicrm-{core,backdrop,drupal,packages,wordpress,joomla}` specifically,
+      // it appears that all callers use 'html-header' (either implicitly or explicitly).
+      throw new \CRM_Core_Exception("Error: addCoreResources only supports html-header");
+    }
     if (!isset($this->addedCoreResources[$region]) && !self::isAjaxMode()) {
       $this->addedCoreResources[$region] = TRUE;
       $config = CRM_Core_Config::singleton();
@@ -616,6 +623,13 @@ class CRM_Core_Resources {
    * @return CRM_Core_Resources
    */
   public function addCoreStyles($region = 'html-header') {
+    if ($region !== 'html-header') {
+      // The signature of this method allowed different regions. However, this
+      // doesn't appear to be used - based on grepping `universe` generally
+      // and `civicrm-{core,backdrop,drupal,packages,wordpress,joomla}` specifically,
+      // it appears that all callers use 'html-header' (either implicitly or explicitly).
+      throw new \CRM_Core_Exception("Error: addCoreResources only supports html-header");
+    }
     if (!isset($this->addedCoreStyles[$region])) {
       $this->addedCoreStyles[$region] = TRUE;