Skip to content

Commit

Permalink
RecentItems - Use font-awesome icons in recent items sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Apr 3, 2022
1 parent d104160 commit 3ba62ab
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
9 changes: 7 additions & 2 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ public static function create(&$params) {
if (!isset($activity->parent_id)) {
$recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId);
// add the recently created Activity
$activityTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id');
$field = Civi\Api4\Activity::getFields(FALSE)
->addWhere('name', '=', 'activity_type_id')
->setLoadOptions(['id', 'label', 'icon'])
->execute()->single();
$activityTypes = array_column($field['options'], NULL, 'id');
$activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activity->id, 'subject');

$title = "";
Expand All @@ -505,7 +509,8 @@ public static function create(&$params) {

$title = $title . $recentContactDisplay;
if (!empty($activityTypes[$activity->activity_type_id])) {
$title .= ' (' . $activityTypes[$activity->activity_type_id] . ')';
$title .= ' (' . $activityTypes[$activity->activity_type_id]['label'] . ')';
$recentOther['icon'] = $activityTypes[$activity->activity_type_id]['icon'] ?? NULL;
}

CRM_Utils_Recent::add($title,
Expand Down
11 changes: 10 additions & 1 deletion CRM/Activity/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,21 @@ public function preProcess() {
if ($this->_action & CRM_Core_Action::VIEW) {
$this->_values['details'] = CRM_Utils_String::purifyHtml($this->_values['details'] ?? '');
$url = CRM_Utils_System::url(implode("/", $this->urlPath), "reset=1&id={$this->_activityId}&action=view&cid={$this->_values['source_contact_id']}");
$field = Civi\Api4\Activity::getFields(FALSE)
->addWhere('name', '=', 'activity_type_id')
->setLoadOptions(['id', 'label', 'icon'])
->execute()->single();
$activityTypes = array_column($field['options'], NULL, 'id');
$info = [
'icon' => $activityTypes[$this->_values['activity_type_id']]['icon'] ?? NULL,
];
CRM_Utils_Recent::add(CRM_Utils_Array::value('subject', $this->_values, ts('(no subject)')),
$url,
$this->_values['id'],
'Activity',
$this->_values['source_contact_id'],
$this->_values['source_contact']
$this->_values['source_contact'],
$info
);
}
}
Expand Down
11 changes: 10 additions & 1 deletion CRM/Activity/Form/ActivityView.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,21 @@ public function preProcess() {
$this->assign('values', $values);

$url = CRM_Utils_System::url(implode("/", $this->urlPath), "reset=1&id={$activityId}&action=view&cid={$defaults['source_contact_id']}");
$field = Civi\Api4\Activity::getFields(FALSE)
->addWhere('name', '=', 'activity_type_id')
->setLoadOptions(['id', 'label', 'icon'])
->execute()->single();
$activityTypes = array_column($field['options'], NULL, 'id');
$info = [
'icon' => $activityTypes[$this->_values['activity_type_id']]['icon'] ?? NULL,
];
CRM_Utils_Recent::add($defaults['subject'],
$url,
$activityId,
'Activity',
$defaults['source_contact_id'],
$defaults['source_contact']
$defaults['source_contact'],
$info
);
}

Expand Down
27 changes: 27 additions & 0 deletions CRM/Utils/Recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static function add(
'image_url' => $others['imageUrl'] ?? NULL,
'edit_url' => $others['editUrl'] ?? NULL,
'delete_url' => $others['deleteUrl'] ?? NULL,
'icon' => $others['icon'] ?? self::getIcon($type, $others['subtype'] ?? NULL),
]
);

Expand All @@ -136,6 +137,32 @@ public static function add(
$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 ($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
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Block/RecentlyViewed.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{if $item.image_url}
<span class="icon crm-icon {if $item.subtype}{$item.subtype}{else}{$item.type}{/if}-icon" style="background: url('{$item.image_url}')"></span>
{else}
<span class="icon crm-icon {$item.type}{if $item.subtype}-subtype{/if}-icon"></span>
<i class="crm-i fa-fw {$item.icon}"></i>
{/if}
{if $item.isDeleted}<del>{/if}{$item.title}{if $item.isDeleted}</del>{/if}
</a>
Expand Down

0 comments on commit 3ba62ab

Please sign in to comment.