From 42aa58130e4e13b00135282703bb510d0f2d1f63 Mon Sep 17 00:00:00 2001 From: Bradley Taylor Date: Sat, 5 Mar 2022 15:26:43 +0000 Subject: [PATCH] Avoid e-notices on pages with tabs --- CRM/Core/Form.php | 2 +- CRM/Core/Page.php | 2 ++ CRM/Core/Smarty.php | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 88ae11e9be1e..ae31027817d8 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -719,7 +719,7 @@ public function buildForm() { // our ensured variables get blown away, so we need to set them even if // it's already been initialized. self::$_template->ensureVariablesAreAssigned($this->expectedSmartyVariables); - + self::$_template->addExpectedTabHeaderKeys(); } /** diff --git a/CRM/Core/Page.php b/CRM/Core/Page.php index 4194e9bda745..7f9e785610f9 100644 --- a/CRM/Core/Page.php +++ b/CRM/Core/Page.php @@ -199,6 +199,8 @@ public function run() { $pageTemplateFile = $this->getHookedTemplateFileName(); self::$_template->assign('tplFile', $pageTemplateFile); + self::$_template->addExpectedTabHeaderKeys(); + // invoke the pagRun hook, CRM-3906 CRM_Utils_Hook::pageRun($this); diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index bcd9c69d91bd..c7476e9b94f4 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -202,6 +202,26 @@ public function ensureVariablesAreAssigned(array $variables): void { } } + /** + * 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) *