From 91b0ba434a5f6216824bb5aaf8acd217cd765187 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 25 Nov 2021 19:40:10 +1300 Subject: [PATCH] Assign variable to determine whether to show email signature field This gets us around complex 'empty checks' and allows us to avoid enotices in smarty --- CRM/Contact/Form/Edit/Email.php | 31 +++++++++++------------ templates/CRM/Contact/Form/Edit/Email.tpl | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/CRM/Contact/Form/Edit/Email.php b/CRM/Contact/Form/Edit/Email.php index c75865bd82..f6c1a3cbec 100644 --- a/CRM/Contact/Form/Edit/Email.php +++ b/CRM/Contact/Form/Edit/Email.php @@ -66,33 +66,32 @@ class CRM_Contact_Form_Edit_Email { //Bulkmail checkbox $form->assign('multipleBulk', $multipleBulk); - $js = ['id' => "Email_" . $blockId . "_IsBulkmail" , 'aria-label' => ts('Bulk Mailing for Email %1?', [1 => $blockId])]; + $js = ['id' => 'Email_' . $blockId . '_IsBulkmail', 'aria-label' => ts('Bulk Mailing for Email %1?', [1 => $blockId])]; if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('advcheckbox', "email[$blockId][is_bulkmail]", NULL, '', $js); //is_Primary radio - $js = ['id' => "Email_" . $blockId . "_IsPrimary", 'aria-label' => ts('Email %1 is primary?', [1 => $blockId])]; + $js = ['id' => 'Email_' . $blockId . '_IsPrimary', 'aria-label' => ts('Email %1 is primary?', [1 => $blockId])]; if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('radio', "email[$blockId][is_primary]", '', '', '1', $js); - - if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') { - // Only display the signature fields if this contact has a CMS account - // because they can only send email if they have access to the CRM - if (!empty($form->_contactId)) { - $ufID = CRM_Core_BAO_UFMatch::getUFId($form->_contactId); - if ($ufID) { - $form->add('textarea', "email[$blockId][signature_text]", ts('Signature (Text)'), - ['rows' => 2, 'cols' => 40] - ); - $form->add('wysiwyg', "email[$blockId][signature_html]", ts('Signature (HTML)'), - ['rows' => 2, 'cols' => 40] - ); - } + // Only display the signature fields if this contact has a CMS account + // because they can only send email if they have access to the CRM + $isAddSignatureFields = $form instanceof \CRM_Contact_Form_Contact && !empty($form->_contactId); + $form->assign('isAddSignatureFields', $isAddSignatureFields); + if ($isAddSignatureFields) { + $ufID = CRM_Core_BAO_UFMatch::getUFId($form->_contactId); + if ($ufID) { + $form->add('textarea', "email[$blockId][signature_text]", ts('Signature (Text)'), + ['rows' => 2, 'cols' => 40] + ); + $form->add('wysiwyg', "email[$blockId][signature_html]", ts('Signature (HTML)'), + ['rows' => 2, 'cols' => 40] + ); } } } diff --git a/templates/CRM/Contact/Form/Edit/Email.tpl b/templates/CRM/Contact/Form/Edit/Email.tpl index 4c4988f17e..b840175155 100644 --- a/templates/CRM/Contact/Form/Edit/Email.tpl +++ b/templates/CRM/Contact/Form/Edit/Email.tpl @@ -26,7 +26,7 @@ {$form.email.$blockId.email.html|crmAddClass:email} {$form.email.$blockId.location_type_id.html} - {if $className eq 'CRM_Contact_Form_Contact' and !empty($form.email.$blockId.signature_html.html)} + {if $isAddSignatureFields}