public $_toContactEmails = array();
/**
+ * Generate an array of Domain email addresses.
+ * @return array $domainEmails;
+ */
+ public static function domainEmails() {
+ $domainEmails = array();
+ $domainFrom = CRM_Core_OptionGroup::values('from_email_address');
+ foreach (array_keys($domainFrom) as $k) {
+ $domainEmail = $domainFrom[$k];
+ $domainEmails[$domainEmail] = htmlspecialchars($domainEmail);
+ }
+ return $domainEmails;
+ }
+
+ /**
+ * Pre Process Form Addresses to be used in QUickfomr
* @param CRM_Core_Form $form
+ * @param bool $bounce determine if we want to throw a status bounce.
*/
- public static function preProcessFromAddress(&$form) {
+ public static function preProcessFromAddress(&$form, $bounce = TRUE) {
$form->_single = FALSE;
$className = CRM_Utils_System::getClassName($form);
if (property_exists($form, '_context') &&
$form->_noEmails = FALSE;
}
}
+ if (!empty($email)) {
+ $form->_emails[$emailId] = $emails[$emailId];
+ $emails[$emailId] .= $item['locationType'];
- $form->_emails[$emailId] = $emails[$emailId];
- $emails[$emailId] .= $item['locationType'];
-
- if ($item['is_primary']) {
- $emails[$emailId] .= ' ' . ts('(preferred)');
+ if ($item['is_primary']) {
+ $emails[$emailId] .= ' ' . ts('(preferred)');
+ }
+ $emails[$emailId] = htmlspecialchars($emails[$emailId]);
}
- $emails[$emailId] = htmlspecialchars($emails[$emailId]);
}
$form->assign('noEmails', $form->_noEmails);
- if ($form->_noEmails) {
- CRM_Core_Error::statusBounce(ts('Your user record does not have a valid email address'));
+ if ($bounce) {
+ if ($form->_noEmails) {
+ CRM_Core_Error::statusBounce(ts('Your user record does not have a valid email address'));
+ }
}
// now add domain from addresses
- $domainEmails = array();
- $domainFrom = CRM_Core_OptionGroup::values('from_email_address');
- foreach (array_keys($domainFrom) as $k) {
- $domainEmail = $domainFrom[$k];
- $domainEmails[$domainEmail] = htmlspecialchars($domainEmail);
+ $domainEmails = self::domainEmails();
+ foreach ($domainEmails as $domainEmail => $email) {
$form->_emails[$domainEmail] = $domainEmail;
}
-
$form->_fromEmails = CRM_Utils_Array::crmArrayMerge($emails, $domainEmails);
-
- // Add signature
- $defaultEmail = civicrm_api3('email', 'getsingle', array('id' => key($form->_fromEmails)));
- $defaults = array();
- if (!empty($defaultEmail['signature_html'])) {
- $defaults['html_message'] = '<br/><br/>--' . $defaultEmail['signature_html'];
+ foreach ($form->_fromEmails as $key => $fromEmail) {
+ if (empty($fromEmail)) {
+ unset($form->_fromEmails[$key]);
+ }
}
- if (!empty($defaultEmail['signature_text'])) {
- $defaults['text_message'] = "\n\n--\n" . $defaultEmail['signature_text'];
+ if (!empty($emails)) {
+ // Add signature
+ $defaultEmail = civicrm_api3('email', 'getsingle', array('id' => key($form->_fromEmails)));
+ $defaults = array();
+ 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);
}
- $form->setDefaults($defaults);
}
/**
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7 | |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+ /**
+ * Test class for CRM_Contact_Form_Task_EmailCommon.
+ * @group headless
+ */
+class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+ $this->_contactIds = array(
+ $this->individualCreate(array('first_name' => 'Antonia', 'last_name' => 'D`souza')),
+ $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')),
+ );
+ $this->_optionValue = $this->callApiSuccess('optionValue', 'create', array(
+ 'label' => '"Seamus Lee" <seamus@example.com>',
+ 'option_group_id' => 'from_email_address',
+ ));
+ }
+
+ /**
+ * Test generating domain emails
+ */
+ public function testDomainEmailGeneation() {
+ $emails = CRM_Contact_Form_Task_EmailCommon::domainEmails();
+ $this->assertNotEmpty($emails);
+ $optionValue = $this->callAPISuccess('OptionValue', 'Get', array(
+ 'id' => $this->_optionValue['id'],
+ ));
+ $this->assertTrue(array_key_exists('"Seamus Lee" <seamus@example.com>', $emails));
+ $this->assertEquals('"Seamus Lee" <seamus@example.com>', $optionValue['values'][$this->_optionValue['id']]['label']);
+ }
+
+}