From: Bradley Taylor Date: Wed, 22 Dec 2021 15:29:21 +0000 (+0000) Subject: "Open in new tab" on .crm-summary-link icons should open contact page, not summary... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2ba5b7f7f5505c956487f1c116b22119aab6b754;p=civicrm-core.git "Open in new tab" on .crm-summary-link icons should open contact page, not summary content. Whilst the contact image tooltip is set to preventDefault, it is still possible to copy the URL or open in new tab. This change ensures that the correct URL is set in these situations. Backwards compatiability is retained for third parties using the crm-tooltip class without the new data attribute. --- diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 170ddec540..b70eee50af 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -27,11 +27,14 @@ class CRM_Contact_BAO_Contact_Utils { * Contact id. * @param bool $addProfileOverlay * If profile overlay class should be added. + * @param string $contactUrl + * URL to the contact page. Defaults to civicrm/contact/view * * @return string * @throws \CRM_Core_Exception */ - public static function getImage($contactType, $urlOnly = FALSE, $contactId = NULL, $addProfileOverlay = TRUE) { + public static function getImage($contactType, $urlOnly = FALSE, $contactId = NULL, $addProfileOverlay = TRUE, $contactUrl = NULL) { + static $imageInfo = []; $contactType = CRM_Utils_Array::explodePadded($contactType); @@ -79,11 +82,14 @@ class CRM_Contact_BAO_Contact_Utils { $summaryOverlayProfileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'summary_overlay', 'id', 'name'); } + $contactURL = $contactUrl ?: CRM_Utils_System::url('civicrm/contact/view', + "reset=1&cid={$contactId}" + ); $profileURL = CRM_Utils_System::url('civicrm/profile/view', "reset=1&gid={$summaryOverlayProfileId}&id={$contactId}&snippet=4&is_show_email_task=1" ); - $imageInfo[$contactType]['summary-link'] = '' . $imageInfo[$contactType]['image'] . ''; + $imageInfo[$contactType]['summary-link'] = '' . $imageInfo[$contactType]['image'] . ''; } else { $imageInfo[$contactType]['summary-link'] = $imageInfo[$contactType]['image']; diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index cfc35d70ef..872004d475 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -833,9 +833,14 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se // allow components to add more actions CRM_Core_Component::searchAction($row, $result->contact_id); + $contactUrl = CRM_Utils_System::url('civicrm/contact/view', + "reset=1&cid={$result->contact_id}&key={$this->_key}&context={$this->_context}" + ); $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, - $result->contact_id + $result->contact_id, + TRUE, + $contactUrl ); $row['contact_type_orig'] = $result->contact_sub_type ? $result->contact_sub_type : $result->contact_type; @@ -990,8 +995,15 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se CRM_Core_Component::searchAction($row, $row['contact_id']); if (!empty($row['contact_type_orig'])) { + $contactUrl = CRM_Utils_System::url('civicrm/contact/view', + "reset=1&cid={$row['contact_id']}&key={$this->_key}&context={$this->_context}" + ); $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($row['contact_type_orig'], - FALSE, $row['contact_id']); + FALSE, + $row['contact_id'], + TRUE, + $contactUrl + ); } } } diff --git a/js/Common.js b/js/Common.js index f5601ed8c0..e24b9dadf7 100644 --- a/js/Common.js +++ b/js/Common.js @@ -1148,10 +1148,11 @@ if (!CRM.vars) CRM.vars = {}; $(this).addClass('crm-tooltip-down'); } if (!$(this).children('.crm-tooltip-wrapper').length) { + var tooltipContents = $(this)[0].hasAttribute('data-tooltip-url') ? $(this).attr('data-tooltip-url') : this.href; $(this).append('
'); $(this).children().children('.crm-tooltip') .html('
') - .load(this.href); + .load(tooltipContents); } }) .on('mouseleave', 'a.crm-summary-link', function () { diff --git a/tests/phpunit/CRM/Activity/Form/SearchTest.php b/tests/phpunit/CRM/Activity/Form/SearchTest.php index c0c98fded5..c1e73def18 100644 --- a/tests/phpunit/CRM/Activity/Form/SearchTest.php +++ b/tests/phpunit/CRM/Activity/Form/SearchTest.php @@ -42,7 +42,7 @@ class CRM_Activity_Form_SearchTest extends CiviUnitTestCase { $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 ed157fc677..9d879397d0 100644 --- a/tests/phpunit/CRM/Financial/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Financial/Page/AjaxTest.php @@ -42,7 +42,7 @@ class CRM_Financial_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST['return'] = TRUE; $json = CRM_Financial_Page_AJAX::getFinancialTransactionsList(); $json = str_replace(rtrim(CIVICRM_UF_BASEURL, '/'), 'http://FIX ME', $json); - $this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","assertEquals('{"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"]] }', $json); @@ -66,7 +66,7 @@ class CRM_Financial_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST['return'] = TRUE; $json = CRM_Financial_Page_AJAX::getFinancialTransactionsList(); $json = str_replace(rtrim(CIVICRM_UF_BASEURL, '/'), 'http://FIX ME', $json); - $this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","","Anderson, Anthony","$ 5.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",' . '"Credit Card","Completed","Donation","ViewAssign"]] }', $json); diff --git a/tests/phpunit/CRM/Member/Selector/SearchTest.php b/tests/phpunit/CRM/Member/Selector/SearchTest.php index d9f946cb04..01e599b45c 100644 --- a/tests/phpunit/CRM/Member/Selector/SearchTest.php +++ b/tests/phpunit/CRM/Member/Selector/SearchTest.php @@ -35,7 +35,7 @@ class CRM_Member_Selector_SearchTest extends CiviUnitTestCase { $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 c5692825ae..fb6562b4aa 100644 --- a/tests/phpunit/CRM/Pledge/Form/SearchTest.php +++ b/tests/phpunit/CRM/Pledge/Form/SearchTest.php @@ -53,7 +53,7 @@ class CRM_Pledge_Form_SearchTest extends CiviUnitTestCase { 'pledge_status_name' => 'Pending Label**', 'checkbox' => 'mark_x_1', 'action' => 'ViewEditmore', - 'contact_type' => '
', + 'contact_type' => '
', ], $rows[0]); }