Ensure beginHookFormElements is assigned
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 7 Nov 2021 22:26:15 +0000 (11:26 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 7 Nov 2021 22:26:15 +0000 (11:26 +1300)
This ensures the variable is assigned & hence does not enotice with escape on output

CRM/Core/Form.php
templates/CRM/Form/body.tpl

index fce332f774fcc34f6edf5f78b0103b7bc44700c8..9aff42aa6c36176c542a6d28f3d87308eafe4749 100644 (file)
@@ -253,6 +253,18 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     'color',
   ];
 
+  /**
+   * Variables smarty expects to have set.
+   *
+   * We ensure these are assigned (value = NULL) when Smarty is instantiated in
+   * order to avoid e-notices / having to use empty or isset in the template layer.
+   *
+   * @var string[]
+   */
+  public $expectedSmartyVariables = [
+    'beginHookFormElements',
+  ];
+
   /**
    * Constructor for the basic form page.
    *
@@ -297,6 +309,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     // let the constructor initialize this, should happen only once
     if (!isset(self::$_template)) {
       self::$_template = CRM_Core_Smarty::singleton();
+      self::$_template->ensureVariablesAreAssigned($this->expectedSmartyVariables);
     }
     // Workaround for CRM-15153 - give each form a reasonably unique css class
     $this->addClass(CRM_Utils_System::getClassName($this));
index a34e7a835cdadf645b078130b8c92cae01e94789..b834269024f5142ff2e5a6ad3ff076728612e0fb 100644 (file)
@@ -32,7 +32,7 @@
 {/if}
 
 {* Add all the form elements sent in by the hook - used by civiDiscount and a few other extensions *}
-{if !empty($beginHookFormElements)}
+{if $beginHookFormElements}
   <table class="form-layout-compressed">
   {foreach from=$beginHookFormElements key=dontCare item=hookFormElement}
       <tr><td class="label nowrap">{$form.$hookFormElement.label}</td><td>{$form.$hookFormElement.html}</td></tr>