From faed105bac8ca8c44a860109437f3e2191310a5e Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 2 Nov 2021 10:23:03 +1300 Subject: [PATCH] Use null variables rather than isset in Core_Block This removes an isset from LangSwitch and some enotices that we see if escape on output is enabled. 'langSwitch' is normally always assigned by the smarty initialize but for some reason not via this path --- CRM/Core/Block.php | 1 + CRM/Core/Smarty.php | 13 +++++++++++++ templates/CRM/Block/LangSwitch.tpl | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CRM/Core/Block.php b/CRM/Core/Block.php index 1d7a605a29..8394310dc2 100644 --- a/CRM/Core/Block.php +++ b/CRM/Core/Block.php @@ -552,6 +552,7 @@ class CRM_Core_Block { if ($config->isUpgradeMode()) { return NULL; } + CRM_Core_Smarty::singleton()->ensureVariablesAreAssigned(['langSwitch', 'breadcrumb', 'pageTitle']); if (!self::getProperty($id, 'active')) { return NULL; diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index b73df97307..9f805c9c8d 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -187,6 +187,19 @@ class CRM_Core_Smarty extends Smarty { return $output; } + /** + * Ensure these variables are set to make it easier to access them without e-notice. + * + * @param array $variables + */ + public function ensureVariablesAreAssigned(array $variables): void { + foreach ($variables as $variable) { + if (!isset($this->get_template_vars()[$variable])) { + $this->assign($variable); + } + } + } + /** * Fetch a template (while using certain variables) * diff --git a/templates/CRM/Block/LangSwitch.tpl b/templates/CRM/Block/LangSwitch.tpl index 4f708ccc25..1bdfb660ab 100644 --- a/templates/CRM/Block/LangSwitch.tpl +++ b/templates/CRM/Block/LangSwitch.tpl @@ -7,7 +7,7 @@ | and copyright information, see https://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{if isset($langSwitch) and $langSwitch|@count > 1} +{if $langSwitch|@count > 1}