Skip to content

Commit

Permalink
Merge pull request #21957 from eileenmcnaughton/lang
Browse files Browse the repository at this point in the history
Use null variables rather than isset in Core_Block
  • Loading branch information
eileenmcnaughton authored Nov 4, 2021
2 parents 49dca11 + faed105 commit 39bc566
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CRM/Core/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ public static function getContent($id) {
if ($config->isUpgradeMode()) {
return NULL;
}
CRM_Core_Smarty::singleton()->ensureVariablesAreAssigned(['langSwitch', 'breadcrumb', 'pageTitle']);

if (!self::getProperty($id, 'active')) {
return NULL;
Expand Down
13 changes: 13 additions & 0 deletions CRM/Core/Smarty.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@ public function fetch($resource_name, $cache_id = NULL, $compile_id = NULL, $dis
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)
*
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Block/LangSwitch.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 39bc566

Please sign in to comment.