* @param CRM_Core_Form $form
* @param bool $bounce determine if we want to throw a status bounce.
*
- * @throws \CiviCRM_API3_Exception
+ * @throws \API_Exception
*/
public static function preProcessFromAddress(&$form, $bounce = TRUE) {
$form->_emails = [];
$form->_emails = $fromEmailValues;
$defaults = [];
$form->_fromEmails = $fromEmailValues;
+ if (is_numeric(key($form->_fromEmails))) {
+ $emailID = (int) key($form->_fromEmails);
+ $defaults = CRM_Core_BAO_Email::getEmailSignatureDefaults($emailID);
+ }
if (!Civi::settings()->get('allow_mail_from_logged_in_contact')) {
$defaults['from_email_address'] = current(CRM_Core_BAO_Domain::getNameAndEmail(FALSE, TRUE));
}
- if (is_numeric(key($form->_fromEmails))) {
- // Add signature
- $defaultEmail = civicrm_api3('email', 'getsingle', ['id' => key($form->_fromEmails)]);
- $defaults = [];
- if (!empty($defaultEmail['signature_html'])) {
- $defaults['html_message'] = '<br/><br/>--' . $defaultEmail['signature_html'];
- }
- if (!empty($defaultEmail['signature_text'])) {
- $defaults['text_message'] = "\n\n--\n" . $defaultEmail['signature_text'];
- }
- }
$form->setDefaults($defaults);
}
* Call trait preProcess function.
*
* This function exists as a transitional arrangement so classes overriding
- * preProcess can still call it. Ideally it will be melded into preProcess later.
+ * preProcess can still call it. Ideally it will be melded into preProcess
+ * later.
*
- * @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
+ * @throws \API_Exception
*/
protected function traitPreProcess() {
CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
+use Civi\Api4\Email;
+
/**
* This class contains functions for email handling.
*/
}
}
+ /**
+ * Get default text for a message with the signature from the email sender populated.
+ *
+ * @param int $emailID
+ *
+ * @return array
+ *
+ * @throws \API_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
+ */
+ public static function getEmailSignatureDefaults(int $emailID): array {
+ // Add signature
+ $defaultEmail = Email::get(FALSE)
+ ->addSelect('signature_html', 'signature_text')
+ ->addWhere('id', '=', $emailID)->execute()->first();
+ return [
+ 'html_message' => empty($defaultEmail['signature_html']) ? '' : '<br/><br/>--' . $defaultEmail['signature_html'],
+ 'text_message' => empty($defaultEmail['signature_text']) ? '' : "\n\n--\n" . $defaultEmail['signature_text'],
+ ];
+ }
+
}