Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ref] extract function to getEmailDefaults #21067

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Ref] extract function to getEmailDefaults
Part of terminally deprecating the EmailCommon class
  • Loading branch information
eileenmcnaughton committed Aug 10, 2021
commit d7b498bcf90af9e96fce254690279cfffef81dac
17 changes: 5 additions & 12 deletions CRM/Contact/Form/Task/EmailCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CRM_Contact_Form_Task_EmailCommon {
* @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 = [];
Expand All @@ -49,20 +49,13 @@ public static function preProcessFromAddress(&$form, $bounce = TRUE) {
$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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this up seems like it would fix resetting defaults where it seems the intent was to default to the logged in contact, although it seems to do that before anyway so 🤷

This PR seems ok but I am seeing a weird thing on my local so just want to check that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demeritcowboy ueah I read the setting & then potentially usetting of defaults as a mistake - maybe I'm wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow where did the last 12 hours go? The patch is stale now - EmailCommon doesn't git-apply.

Otherwise if I make those changes manually it seems fine. I'll put up a PR for the thing I was seeing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demeritcowboy should I rebase or will this be superceded & perhaps closable with your patch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it should be rebased - my thing ended up being unrelated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - rebased

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks - merge-on-pass'd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

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);
}

Expand Down
5 changes: 3 additions & 2 deletions CRM/Contact/Form/Task/EmailTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ public function preProcess() {
* 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);
Expand Down
23 changes: 23 additions & 0 deletions CRM/Core/BAO/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use Civi\Api4\Email;

/**
* This class contains functions for email handling.
*/
Expand Down Expand Up @@ -383,4 +385,25 @@ public static function updateContactName($contactId, string $primaryEmail) {
}
}

/**
* 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'],
];
}

}