Php8.x Fix notices when creating custom field
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 19 Sep 2023 10:23:45 +0000 (22:23 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 19 Sep 2023 10:23:45 +0000 (22:23 +1200)
CRM/Custom/Form/Field.php
templates/CRM/Custom/Form/Field.tpl

index a61292f666d6054aef5b12ba474127bcf1931620..9a8c2e3d7362462057d5f10a26084748fcf30705 100644 (file)
@@ -238,7 +238,8 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       'select' => ['minimumInputLength' => 0],
     ]);
 
-    if ($this->_action == CRM_Core_Action::UPDATE) {
+    $isUpdateAction = $this->_action == CRM_Core_Action::UPDATE;
+    if ($isUpdateAction) {
       $this->freeze('data_type');
       if (!empty($this->_values['option_group_id'])) {
         $this->assign('hasOptionGroup', in_array($this->_values['html_type'], self::$htmlTypesWithOptions));
@@ -247,12 +248,10 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
         $optionGroupParams['id'] = $this->_values['option_group_id'];
         $optionGroupParams['options']['or'] = [["is_reserved", "id"]];
       }
-      $this->assign('originalHtmlType', $this->_values['html_type']);
-      $this->assign('originalSerialize', $this->_values['serialize']);
-      if (!empty($this->_values['serialize'])) {
-        $this->assign('existingMultiValueCount', $this->getMultiValueCount());
-      }
     }
+    $this->assign('existingMultiValueCount', ($isUpdateAction && !empty($this->_values['serialize'])) ? $this->getMultiValueCount() : NULL);
+    $this->assign('originalSerialize', $isUpdateAction ? $this->_values['serialize'] : NULL);
+    $this->assign('originalHtmlType', $isUpdateAction ? $this->_values['html_type'] : NULL);
 
     // Retrieve optiongroups for selection list
     $optionGroupMetadata = civicrm_api3('OptionGroup', 'get', $optionGroupParams);
index 68733a0d087c7b124e3874f35b647e4ea0840c92..2cfe7802b6ca6b2b8c1e90e9c828615d090dc22e 100644 (file)
@@ -33,7 +33,7 @@
       <td class="label">{$form.serialize.label}</td>
       <td class="html-adjust">{$form.serialize.html}</td>
     </tr>
-    {if !empty($form.in_selector)}
+    {if array_key_exists('in_selector', $form)}
       <tr class='crm-custom-field-form-block-in_selector'>
         <td class='label'>{$form.in_selector.label}</td>
         <td class='html-adjust'>{$form.in_selector.html} {help id="id-in_selector"}</td>