diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 056f792c290f..7e5477e18e04 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -80,7 +80,7 @@ public static function getImage($contactType, $urlOnly = FALSE, $contactId = NUL } $profileURL = CRM_Utils_System::url('civicrm/profile/view', - "reset=1&gid={$summaryOverlayProfileId}&id={$contactId}&snippet=4" + "reset=1&gid={$summaryOverlayProfileId}&id={$contactId}&snippet=4&is_show_email_task=1" ); $imageInfo[$contactType]['summary-link'] = '' . $imageInfo[$contactType]['image'] . ''; diff --git a/CRM/Profile/Page/Dynamic.php b/CRM/Profile/Page/Dynamic.php index 67f7edf0d508..7ce7eeef62bb 100644 --- a/CRM/Profile/Page/Dynamic.php +++ b/CRM/Profile/Page/Dynamic.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Email; + /** * * @package CRM @@ -78,6 +80,13 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { protected $_recordId = NULL; + /** + * Should the primary email be converted into a link, if emailabe. + * + * @var bool + */ + protected $isShowEmailTaskLink = FALSE; + /** * * fetch multirecord as well as non-multirecord fields @@ -97,15 +106,18 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { * @param bool $skipPermission * @param null $profileIds * - * @return \CRM_Profile_Page_Dynamic + * @param bool $isShowEmailTaskLink + * + * @throws \CRM_Core_Exception */ - public function __construct($id, $gid, $restrict, $skipPermission = FALSE, $profileIds = NULL) { + public function __construct($id, $gid, $restrict, $skipPermission = FALSE, $profileIds = NULL, $isShowEmailTaskLink = FALSE) { parent::__construct(); $this->_id = $id; $this->_gid = $gid; $this->_restrict = $restrict; $this->_skipPermission = $skipPermission; + $this->isShowEmailTaskLink = $isShowEmailTaskLink; if (!array_key_exists('multiRecord', $_GET)) { $this->set('multiRecord', NULL); @@ -315,6 +327,11 @@ public function run() { $labels[$index] = preg_replace('/\s+|\W+/', '_', $name); } + if ($this->isShowEmailTaskLink) { + foreach ($this->getEmailFields($fields) as $fieldName) { + $values[$fields[$fieldName]['title']] = $this->getLinkedEmail($values[$fields[$fieldName]['title']]); + } + } foreach ($values as $title => $value) { $profileFields[$labels[$title]] = [ 'label' => $title, @@ -416,4 +433,47 @@ public function overrideExtraTemplateFileName() { return $fileName ? $fileName : parent::overrideExtraTemplateFileName(); } + /** + * Get the email field as a task link, if not on hold or set to do_not_email. + * + * @param string $email + * + * @return string + * @throws \API_Exception + * @throws \Civi\API\Exception\UnauthorizedException + */ + protected function getLinkedEmail($email): string { + if (!$email) { + return ''; + } + $emailID = Email::get()->setOrderBy(['is_primary' => 'DESC'])->setWhere([['contact_id', '=', $this->_id], ['email', '=', $email], ['on_hold', '=', FALSE], ['contact.is_deceased', '=', FALSE], ['contact.is_deleted', '=', FALSE], ['contact.do_not_email', '=', FALSE]])->execute()->first()['id']; + if (!$emailID) { + return $email; + } + $emailPopupUrl = CRM_Utils_System::url('civicrm/activity/email/add', [ + 'action' => 'add', + 'reset' => '1', + 'email_id' => $emailID, + ], TRUE); + + return '' . $email . ''; + } + + /** + * Get the email fields from within the fields array. + * + * @param array $fields + */ + protected function getEmailFields(array $fields): array { + $emailFields = []; + foreach (array_keys($fields) as $fieldName) { + if (substr($fieldName, 0, 6) === 'email-' + && (is_numeric(substr($fieldName, 6)) || substr($fieldName, 6) === + 'Primary')) { + $emailFields[] = $fieldName; + } + } + return $emailFields; + } + } diff --git a/CRM/Profile/Page/View.php b/CRM/Profile/Page/View.php index 54f563d4e9e4..185980e8ed6f 100644 --- a/CRM/Profile/Page/View.php +++ b/CRM/Profile/Page/View.php @@ -35,6 +35,13 @@ class CRM_Profile_Page_View extends CRM_Core_Page { */ protected $_gid; + /** + * Should the primary email be converted into a link, if emailabe. + * + * @var bool + */ + protected $isShowEmailTaskLink = FALSE; + /** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. @@ -44,6 +51,7 @@ public function preProcess() { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE ); + $this->isShowEmailTaskLink = CRM_Utils_Request::retrieve('is_show_email_task', 'Positive', $this); if (!$this->_id) { $session = CRM_Core_Session::singleton(); $this->_id = $session->get('userID'); @@ -77,7 +85,7 @@ public function preProcess() { $anyContent = TRUE; if ($this->_gid) { - $page = new CRM_Profile_Page_Dynamic($this->_id, $this->_gid, 'Profile', FALSE, $profileIds); + $page = new CRM_Profile_Page_Dynamic($this->_id, $this->_gid, 'Profile', FALSE, $profileIds, $this->isShowEmailTaskLink); $profileGroup = []; $profileGroup['title'] = NULL; $profileGroup['content'] = $page->run(); diff --git a/tests/phpunit/CRM/Activity/Form/SearchTest.php b/tests/phpunit/CRM/Activity/Form/SearchTest.php index a976d2783914..de46b7eeebf1 100644 --- a/tests/phpunit/CRM/Activity/Form/SearchTest.php +++ b/tests/phpunit/CRM/Activity/Form/SearchTest.php @@ -38,7 +38,7 @@ public function testSearch() { $this->assertEquals([ [ 'contact_id' => '3', - 'contact_type' => '
', + 'contact_type' => '
', 'sort_name' => 'Anderson, Anthony', 'display_name' => 'Mr. Anthony Anderson II', 'activity_id' => '1', diff --git a/tests/phpunit/CRM/Financial/Page/AjaxTest.php b/tests/phpunit/CRM/Financial/Page/AjaxTest.php index d6c349bc6130..edef40e678c9 100644 --- a/tests/phpunit/CRM/Financial/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Financial/Page/AjaxTest.php @@ -33,7 +33,7 @@ public function testGetFinancialTransactionsList() { $_REQUEST['return'] = TRUE; $json = CRM_Financial_Page_AJAX::getFinancialTransactionsList(); $json = str_replace(rtrim(CIVICRM_UF_BASEURL, '/'), 'http://FIX ME', $json); - $this->assertEquals($json, '{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","assertEquals($json, '{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","","Anderson, Anthony","$ 100.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",' . '"Credit Card","Completed","Donation","View"]] }'); diff --git a/tests/phpunit/CRM/Member/Selector/SearchTest.php b/tests/phpunit/CRM/Member/Selector/SearchTest.php index 3eafc2979116..55e50139b67e 100644 --- a/tests/phpunit/CRM/Member/Selector/SearchTest.php +++ b/tests/phpunit/CRM/Member/Selector/SearchTest.php @@ -35,7 +35,7 @@ public function testSelectorGetRows() { $this->assertEquals([ 'contact_id' => $this->_contactID, 'membership_id' => $membershipID, - 'contact_type' => '
', + 'contact_type' => '
', 'sort_name' => 'Anderson, Anthony', 'membership_type' => 'General', 'membership_join_date' => date('Y-m-d'), diff --git a/tests/phpunit/CRM/Pledge/Form/SearchTest.php b/tests/phpunit/CRM/Pledge/Form/SearchTest.php index 9e34d8099be0..d8bba2d71ce4 100644 --- a/tests/phpunit/CRM/Pledge/Form/SearchTest.php +++ b/tests/phpunit/CRM/Pledge/Form/SearchTest.php @@ -53,7 +53,7 @@ public function testSearch() { 'pledge_status_name' => 'Pending Label**', 'checkbox' => 'mark_x_1', 'action' => 'ViewEditmore', - 'contact_type' => '
', + 'contact_type' => '
', ], $rows[0]); }