From 7a673a8ec369cc9434e2c79376bbbc93d33c8cd0 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 22 Aug 2022 10:29:08 +1200 Subject: [PATCH] Fix email notices on email edit block --- CRM/Contact/Form/Edit/Email.php | 16 +--------------- CRM/Contact/Form/Location.php | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CRM/Contact/Form/Edit/Email.php b/CRM/Contact/Form/Edit/Email.php index 0808b5b055..db08baa6b7 100644 --- a/CRM/Contact/Form/Edit/Email.php +++ b/CRM/Contact/Form/Edit/Email.php @@ -33,6 +33,7 @@ class CRM_Contact_Form_Edit_Email { public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$blockCount) { + CRM_Core_Error::deprecatedWarning('pass in blockCount'); $blockId = ($form->get('Email_Block_Count')) ? $form->get('Email_Block_Count') : 1; } else { @@ -83,21 +84,6 @@ class CRM_Contact_Form_Edit_Email { } $form->addElement('radio', "email[$blockId][is_primary]", '', '', '1', $js); - // 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/CRM/Contact/Form/Location.php b/CRM/Contact/Form/Location.php index 519593c08f..e6c734ee7d 100644 --- a/CRM/Contact/Form/Location.php +++ b/CRM/Contact/Form/Location.php @@ -85,10 +85,31 @@ class CRM_Contact_Form_Location { $generateAjaxRequest++; $ajaxRequestBlocks[$blockName][$instance] = TRUE; } + switch ($blockName) { + case 'Email': + CRM_Contact_Form_Edit_Email::buildQuickForm($form, $instance); + // 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 + $ufID = $form->_contactId && CRM_Core_BAO_UFMatch::getUFId($form->_contactId); + $form->assign('isAddSignatureFields', (bool) $ufID); + if ($ufID) { + $form->add('textarea', "email[$instance][signature_text]", ts('Signature (Text)'), + ['rows' => 2, 'cols' => 40] + ); + $form->add('wysiwyg', "email[$instance][signature_html]", ts('Signature (HTML)'), + ['rows' => 2, 'cols' => 40] + ); + } + break; + + default: + // @todo This pattern actually adds complexity compared to filling out a switch statement + // for the limited number of blocks - as we also have to receive the block count + $form->set($blockName . '_Block_Count', $instance); + $formName = 'CRM_Contact_Form_Edit_' . $blockName; + $formName::buildQuickForm($form); + } - $form->set($blockName . '_Block_Count', $instance); - $formName = 'CRM_Contact_Form_Edit_' . $blockName; - $formName::buildQuickForm($form); } } -- 2.25.1