+ /**
+ * Get icon for a particular contact.
+ *
+ * Example: `CRM_Contact_BAO_Contact::getIcon('Contact', 123)`
+ *
+ * @param string $entityName
+ * Always "Contact".
+ * @param int $entityId
+ * Id of the contact.
+ * @throws CRM_Core_Exception
+ */
+ public static function getEntityIcon(string $entityName, int $entityId) {
+ $contactTypes = CRM_Contact_BAO_ContactType::getAllContactTypes();
+ $subTypes = CRM_Utils_Array::explodePadded(CRM_Core_DAO::getFieldValue(parent::class, $entityId, 'contact_sub_type'));
+ foreach ((array) $subTypes as $subType) {
+ if (!empty($contactTypes[$subType]['icon'])) {
+ return $contactTypes[$subType]['icon'];
+ }
+ }
+ // If no sub-type icon, lookup contact type
+ $contactType = CRM_Core_DAO::getFieldValue(parent::class, $entityId, 'contact_type');
+ return $contactTypes[$contactType]['icon'] ?? self::$_icon;
+ }
+