From: Eileen McNaughton Date: Thu, 25 Nov 2021 06:59:23 +0000 (+1300) Subject: Ensure formal_title is assigned to the template. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a8790790b77c04714986baacaef03a0c69c8b9f3;p=civicrm-core.git Ensure formal_title is assigned to the template. This just gets past one enotice in the great juggle --- diff --git a/CRM/Contact/Form/Edit/Individual.php b/CRM/Contact/Form/Edit/Individual.php index 4547b56e33..af646a350c 100644 --- a/CRM/Contact/Form/Edit/Individual.php +++ b/CRM/Contact/Form/Edit/Individual.php @@ -31,7 +31,8 @@ class CRM_Contact_Form_Edit_Individual { * ( 1 for contact summary. * top bar form and 2 for display name edit ) */ - public static function buildQuickForm(&$form, $inlineEditMode = NULL) { + public static function buildQuickForm($form, $inlineEditMode = NULL): void { + $form->addOptionalQuickFormElement('formal_title'); $form->applyFilter('__ALL__', 'trim'); if (!$inlineEditMode || $inlineEditMode == 1) { @@ -46,7 +47,7 @@ class CRM_Contact_Form_Edit_Individual { // Fixme: dear god why? these come out in a format that is NOT the name of the fields. foreach ($nameFields as &$fix) { $fix = str_replace(' ', '_', strtolower($fix)); - if ($fix == 'prefix' || $fix == 'suffix') { + if ($fix === 'prefix' || $fix === 'suffix') { // God, why god? $fix .= '_id'; } diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 9fdf2e8668..dd5c84882e 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1057,7 +1057,27 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } /** - * Get any smarty elements that may not be present in the form. + * Quick form elements which are conditionally added to the form. + * + * Elements in this array will be added to the form at the end if not present + * so that smarty does not e-notice on things like '{if $form.group}' when + * 'group' is not added to the form (e.g when no groups exist). + * + * @var array + */ + protected $optionalQuickFormElements = []; + + /** + * Add an optional element to the optional elements array. + * + * @param string $elementName + */ + public function addOptionalQuickFormElement(string $elementName): void { + $this->optionalQuickFormElements[] = $elementName; + } + + /** + * Get any quick-form elements that may not be present in the form. * * To make life simpler for smarty we ensure they are set to null * rather than unset. This is done at the last minute when $this @@ -1066,7 +1086,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { * @return array */ public function getOptionalQuickFormElements(): array { - return []; + return $this->optionalQuickFormElements; } /** diff --git a/templates/CRM/Contact/Form/Edit/Individual.tpl b/templates/CRM/Contact/Form/Edit/Individual.tpl index ed18ebcd9e..24f529edb3 100644 --- a/templates/CRM/Contact/Form/Edit/Individual.tpl +++ b/templates/CRM/Contact/Form/Edit/Individual.tpl @@ -16,7 +16,7 @@ {$form.prefix_id.html} {/if} - {if !empty($form.formal_title)} + {if $form.formal_title} {$form.formal_title.label}
{$form.formal_title.html}