Merge pull request #24059 from eileenmcnaughton/pledged
[civicrm-core.git] / CRM / Core / Smarty.php
index bcd9c69d91bddd7e9aa8cce5f5d4d1e6f94c0805..483ef374baea205eac63e6b072809ea1c10630c4 100644 (file)
@@ -176,15 +176,22 @@ class CRM_Core_Smarty extends Smarty {
    * @param bool $display
    *
    * @return bool|mixed|string
+   *
+   * @noinspection PhpDocMissingThrowsInspection
+   * @noinspection PhpUnhandledExceptionInspection
    */
   public function fetch($resource_name, $cache_id = NULL, $compile_id = NULL, $display = FALSE) {
     if (preg_match('/^(\s+)?string:/', $resource_name)) {
       $old_security = $this->security;
       $this->security = TRUE;
     }
-    $output = parent::fetch($resource_name, $cache_id, $compile_id, $display);
-    if (isset($old_security)) {
-      $this->security = $old_security;
+    try {
+      $output = parent::fetch($resource_name, $cache_id, $compile_id, $display);
+    }
+    finally {
+      if (isset($old_security)) {
+        $this->security = $old_security;
+      }
     }
     return $output;
   }
@@ -202,6 +209,26 @@ class CRM_Core_Smarty extends Smarty {
     }
   }
 
+  /**
+   * Avoid e-notices on pages with tabs,
+   * by ensuring tabHeader items contain the necessary keys
+   */
+  public function addExpectedTabHeaderKeys(): void {
+    $defaults = [
+      'class' => '',
+      'extra' => '',
+      'icon' => FALSE,
+      'count' => FALSE,
+      'template' => FALSE,
+    ];
+
+    $tabs = $this->get_template_vars('tabHeader');
+    foreach ((array) $tabs as $i => $tab) {
+      $tabs[$i] = array_merge($defaults, $tab);
+    }
+    $this->assign('tabHeader', $tabs);
+  }
+
   /**
    * Fetch a template (while using certain variables)
    *