Skip to content

Commit

Permalink
Merge pull request #22303 from braders/core-2926-crm-summary-links
Browse files Browse the repository at this point in the history
"Open in new tab" on .crm-summary-link icons should open contact page
  • Loading branch information
demeritcowboy authored Dec 29, 2021
2 parents 6e307d3 + 2ba5b7f commit 06cf762
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
10 changes: 8 additions & 2 deletions CRM/Contact/BAO/Contact/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -79,11 +82,14 @@ public static function getImage($contactType, $urlOnly = FALSE, $contactId = NUL
$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'] = '<a href="' . $profileURL . '" class="crm-summary-link">' . $imageInfo[$contactType]['image'] . '</a>';
$imageInfo[$contactType]['summary-link'] = '<a href="' . $contactURL . '" data-tooltip-url="' . $profileURL . '" class="crm-summary-link">' . $imageInfo[$contactType]['image'] . '</a>';
}
else {
$imageInfo[$contactType]['summary-link'] = $imageInfo[$contactType]['image'];
Expand Down
16 changes: 14 additions & 2 deletions CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,14 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
// 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;
Expand Down Expand Up @@ -990,8 +995,15 @@ public function addActions(&$rows) {
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
);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion js/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div class="crm-tooltip-wrapper"><div class="crm-tooltip"></div></div>');
$(this).children().children('.crm-tooltip')
.html('<div class="crm-loading-element"></div>')
.load(this.href);
.load(tooltipContents);
}
})
.on('mouseleave', 'a.crm-summary-link', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Activity/Form/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testSearch(): void {
$this->assertEquals([
[
'contact_id' => '3',
'contact_type' => '<a href="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'sort_name' => 'Anderson, Anthony',
'display_name' => 'Mr. Anthony Anderson II',
'activity_id' => '1',
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Financial/Page/AjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","<a href=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\"><div'
$this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["","<a href=\"/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3\" data-tooltip-url=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\"><div'
. ' class=\"icon crm-icon Individual-icon\"></div></a>","<a href=/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3>Anderson, Anthony</a>","$ 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","<span><a href=\"/index.php?q=civicrm/contact/view/contribution&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=contribution&amp;'
. 'selectedChild=contribute\" class=\"action-item crm-hover-button\" title=\'View Contribution\' >View</a></span>"]] }', $json);
Expand All @@ -66,7 +66,7 @@ public function testGetFinancialTransactionsListOpenBatch() {
$_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": [ ["<input type=\'checkbox\' id=\'mark_x_2\' name=\'mark_x_2\' value=\'1\' onclick=enableActions(\'x\')></input>","<a href=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\"><div'
$this->assertEquals('{"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["<input type=\'checkbox\' id=\'mark_x_2\' name=\'mark_x_2\' value=\'1\' onclick=enableActions(\'x\')></input>","<a href=\"/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3\" data-tooltip-url=\"/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1\" class=\"crm-summary-link\"><div'
. ' class=\"icon crm-icon Individual-icon\"></div></a>","<a href=/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3>Anderson, Anthony</a>","$ 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","<span><a href=\"/index.php?q=civicrm/contact/view/contribution&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=contribution&amp;'
. 'selectedChild=contribute\" class=\"action-item crm-hover-button\" title=\'View Contribution\' >View</a><a href=\"#\" class=\"action-item crm-hover-button disable-action\" title=\'Assign Transaction\' onclick = \"assignRemove( 2,\'assign\' );\">Assign</a></span>"]] }', $json);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Member/Selector/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testSelectorGetRows(): void {
$this->assertEquals([
'contact_id' => $this->_contactID,
'membership_id' => $membershipID,
'contact_type' => '<a href="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=' . $this->_contactID . '&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=' . $this->_contactID . '" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=' . $this->_contactID . '&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'sort_name' => 'Anderson, Anthony',
'membership_type' => 'General',
'membership_join_date' => date('Y-m-d'),
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Pledge/Form/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testSearch() {
'pledge_status_name' => 'Pending Label**',
'checkbox' => 'mark_x_1',
'action' => '<span><a href="/index.php?q=civicrm/contact/view/pledge&amp;reset=1&amp;id=1&amp;cid=3&amp;action=view&amp;context=search&amp;selectedChild=pledge&amp;key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'View Pledge' . "'" . ' >View</a><a href="/index.php?q=civicrm/contact/view/pledge&amp;reset=1&amp;action=update&amp;id=1&amp;cid=3&amp;context=search&amp;key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'Edit Pledge' . "'" . ' >Edit</a></span><span class=' . "'" . 'btn-slide crm-hover-button' . "'" . '>more<ul class=' . "'" . 'panel' . "'" . '><li><a href="/index.php?q=civicrm/contact/view/pledge&amp;reset=1&amp;action=detach&amp;id=1&amp;cid=3&amp;context=search&amp;key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'Cancel Pledge' . "'" . ' onclick = "return confirm(' . "'" . 'Cancelling this pledge will also cancel any scheduled (and not completed) pledge payments. This action cannot be undone. Do you want to continue?' . "'" . ');">Cancel</a></li><li><a href="/index.php?q=civicrm/contact/view/pledge&amp;reset=1&amp;action=delete&amp;id=1&amp;cid=3&amp;context=search&amp;key=' . $qfKey . '" class="action-item crm-hover-button small-popup" title=' . "'" . 'Delete Pledge' . "'" . ' >Delete</a></li></ul></span>',
'contact_type' => '<a href="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
'contact_type' => '<a href="/index.php?q=civicrm/contact/view&amp;reset=1&amp;cid=3" data-tooltip-url="/index.php?q=civicrm/profile/view&amp;reset=1&amp;gid=7&amp;id=3&amp;snippet=4&amp;is_show_email_task=1" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
], $rows[0]);
}

Expand Down

0 comments on commit 06cf762

Please sign in to comment.