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] Copy emailcommon function back to email trait #21251

Merged
merged 1 commit into from
Aug 25, 2021
Merged
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
49 changes: 35 additions & 14 deletions CRM/Contact/Form/Task/EmailTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ trait CRM_Contact_Form_Task_EmailTrait {
*/
public $_toContactIds = [];

/**
* Store only "cc" contact ids.
* @var array
*/
public $_ccContactIds = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused (that's not how we roll now & would just be an enotice if there was an issue)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

(afterwards)


/**
* Store only "bcc" contact ids.
*
* @var array
*/
public $_bccContactIds = [];

/**
* Is the form being loaded from a search action.
*
Expand Down Expand Up @@ -125,7 +112,7 @@ public function preProcess() {
* @throws \API_Exception
*/
protected function traitPreProcess() {
CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
$this->preProcessFromAddress();
if ($this->isSearchContext()) {
// Currently only the contact email form is callable outside search context.
parent::preProcess();
Expand All @@ -137,6 +124,40 @@ protected function traitPreProcess() {
}
}

/**
* Pre Process Form Addresses to be used in Quickform
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
protected function preProcessFromAddress(): void {
$form = $this;
$form->_emails = [];

// @TODO remove these line and to it somewhere more appropriate. Currently some classes (e.g Case
// are having to re-write contactIds afterwards due to this inappropriate variable setting
// If we don't have any contact IDs, use the logged in contact ID
$form->_contactIds = $form->_contactIds ?: [CRM_Core_Session::getLoggedInContactID()];

$fromEmailValues = CRM_Core_BAO_Email::getFromEmail();

if (empty($fromEmailValues)) {
CRM_Core_Error::statusBounce(ts('Your user record does not have a valid email address and no from addresses have been configured.'));
}

$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));
}
$form->setDefaults($defaults);
}

/**
* Build the form object.
*
Expand Down