Skip to content

Commit

Permalink
Merge pull request #26233 from eileenmcnaughton/weight
Browse files Browse the repository at this point in the history
Add weight to links spec
  • Loading branch information
colemanw committed May 17, 2023
2 parents a55e859 + 47d99a2 commit 12c48f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CRM/Contribute/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,21 @@ public static function &links($componentId = NULL, $componentAction = NULL, $key
'url' => 'civicrm/contact/view/contribution',
'qs' => "reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=contribute{$extraParams}",
'title' => ts('View Contribution'),
'weight' => -20,
],
CRM_Core_Action::UPDATE => [
'name' => ts('Edit'),
'url' => 'civicrm/contact/view/contribution',
'qs' => "reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}",
'title' => ts('Edit Contribution'),
'weight' => -10,
],
CRM_Core_Action::DELETE => [
'name' => ts('Delete'),
'url' => 'civicrm/contact/view/contribution',
'qs' => "reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%{$extraParams}",
'title' => ts('Delete Contribution'),
'weight' => 100,
],
];
}
Expand Down
4 changes: 4 additions & 0 deletions CRM/Core/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ public static function formLink(

$url = [];

usort($seqLinks, static function ($a, $b) {
return (int) ((int) ($a['weight'] ?? 0) > (int) ($b['weight'] ?? 0));
});

foreach ($seqLinks as $i => $link) {
if (!$mask || !array_key_exists('bit', $link) || ($mask & $link['bit'])) {
$extra = isset($link['extra']) ? self::replace($link['extra'], $values) : NULL;
Expand Down
11 changes: 7 additions & 4 deletions tests/phpunit/CRM/Activity/BAO/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ public function testRetrieve(): void {
}

/**
* Test Assigning a target contact but then the logged in user cannot see the contact
* Test Assigning a target contact but then the logged in user cannot see the
* contact
*
* @throws \CRM_Core_Exception
*/
public function testTargetContactNotavaliable() {
public function testTargetContactNotAvaliable(): void {
$contactId = $this->individualCreate();
$params = [
'first_name' => 'liz',
Expand Down Expand Up @@ -210,9 +213,9 @@ public function testTargetContactNotavaliable() {
$activityGetParams = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
$activityGetParams += ['contact_id' => $contactId];
$activities = CRM_Activity_BAO_Activity::getContactActivitySelector($activityGetParams);
// Aseert that we have sensible data to display in the contact tab
// Assert that we have sensible data to display in the contact tab
$this->assertEquals('Anderson, Anthony', $activities['data'][0]['source_contact_name']);
// Note that becasue there is a target contact but it is not accessable the output is an empty string not n/a
// Note that because there is a target contact but it is not accessible the output is an empty string not n/a
$this->assertEquals('', $activities['data'][0]['target_contact_name']);
// verify that doing the underlying query shows we get a target contact_id
$this->assertEquals(1, CRM_Activity_BAO_Activity::getActivities(['contact_id' => $contactId])[1]['target_contact_count']);
Expand Down

0 comments on commit 12c48f7

Please sign in to comment.