From 3af57cde6b6694c46e0861e23e2b1912a416c597 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 2 Apr 2022 21:29:49 -0400 Subject: [PATCH] RecentItems - Use font-awesome icons in recent items sidebar --- CRM/Utils/Recent.php | 27 +++++++++++++++++++ templates/CRM/Block/RecentlyViewed.tpl | 2 +- .../phpunit/CRM/Activity/Form/SearchTest.php | 2 +- tests/phpunit/CRM/Financial/Page/AjaxTest.php | 8 +++--- .../CRM/Member/Selector/SearchTest.php | 2 +- tests/phpunit/CRM/Pledge/Form/SearchTest.php | 2 +- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/CRM/Utils/Recent.php b/CRM/Utils/Recent.php index aed16f4132..fc98cc37fe 100644 --- a/CRM/Utils/Recent.php +++ b/CRM/Utils/Recent.php @@ -122,6 +122,7 @@ class CRM_Utils_Recent { 'image_url' => $others['imageUrl'] ?? NULL, 'edit_url' => $others['editUrl'] ?? NULL, 'delete_url' => $others['deleteUrl'] ?? NULL, + 'icon' => $others['icon'] ?? self::getIcon($type, $others['subtype'] ?? NULL), ] ); @@ -136,6 +137,32 @@ class CRM_Utils_Recent { $session->set(self::STORE_NAME, self::$_recent); } + /** + * @param $type + * @param $subType + * @return string|null + */ + private static function getIcon($type, $subType) { + $icon = NULL; + $contactTypes = CRM_Contact_BAO_ContactType::getAllContactTypes(); + if (!empty($contactTypes[$type])) { + // Pick icon from contact sub-type first if available, then contact type + $subTypesAndType = array_merge((array) CRM_Utils_Array::explodePadded($subType), [$type]); + foreach ($subTypesAndType as $contactType) { + $icon = $icon ?? $contactTypes[$contactType]['icon'] ?? NULL; + } + // If no contact type icon, proceed to lookup icon from dao + $type = 'Contact'; + } + if (!$icon) { + $daoClass = CRM_Core_DAO_AllCoreTables::getFullName($type); + if ($daoClass) { + $icon = $daoClass::$_icon; + } + } + return $icon ?: 'fa-gear'; + } + /** * Callback for hook_civicrm_post(). * @param \Civi\Core\Event\PostEvent $event diff --git a/templates/CRM/Block/RecentlyViewed.tpl b/templates/CRM/Block/RecentlyViewed.tpl index e30a6a53b9..4716f9b2cc 100644 --- a/templates/CRM/Block/RecentlyViewed.tpl +++ b/templates/CRM/Block/RecentlyViewed.tpl @@ -17,7 +17,7 @@ {if $item.image_url} {else} - + {/if} {if $item.isDeleted}{/if}{$item.title}{if $item.isDeleted}{/if} diff --git a/tests/phpunit/CRM/Activity/Form/SearchTest.php b/tests/phpunit/CRM/Activity/Form/SearchTest.php index 138195031f..23792a6deb 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 35bff606e9..b3d1801496 100644 --- a/tests/phpunit/CRM/Financial/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Financial/Page/AjaxTest.php @@ -42,8 +42,8 @@ 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": [ ["","","Anderson, Anthony","$100.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",' + $this->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,8 +66,8 @@ 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": [ ["","","Anderson, Anthony","$5.00","12345","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM","' . CRM_Utils_Date::customFormat(date('Ymd')) . ' 12:00 AM",' + $this->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 01e599b45c..709749b9fb 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 fb6562b4aa..a074d68798 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]); } -- 2.25.1