Use null variables rather than isset in Core_Block
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 1 Nov 2021 21:23:03 +0000 (10:23 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 1 Nov 2021 21:23:03 +0000 (10:23 +1300)
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
CRM/Core/Smarty.php
templates/CRM/Block/LangSwitch.tpl

index 1d7a605a29f9eed2f0c8ce666a6459e78a3d8aba..8394310dc289eec61e5356c657aa259cf4738780 100644 (file)
@@ -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;
index b73df9730703e65bb44686aee94ef83e55bc80ee..9f805c9c8d23597c2514770739f364a8e7eba136 100644 (file)
@@ -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)
    *
index 4f708ccc255e21585442e4f54cafeab1c71c75ef..1bdfb660ab8bcad8a1696bb0a1e23976fa17da60 100644 (file)
@@ -7,7 +7,7 @@
  | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
 *}
-{if isset($langSwitch) and $langSwitch|@count > 1}
+{if $langSwitch|@count > 1}
   <form action="#">
     <select name="lcMessages" onchange="window.location='{crmURL q="$queryString"}'+this.value">
       {foreach from=$langSwitch item=language key=locale}