Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #60 - Add ECK entities to RecentItems menu #61

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CRM/Eck/BAO/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,24 @@ public static function getEntityType($entityName) {
return strpos($entityName, 'Eck_') === 0 ? substr($entityName, strlen('Eck_')) : NULL;
}

/**
* @param string $entityName
* @param int $entityId
* @return string
*/
public static function getEntityIcon(string $entityName, int $entityId):?string {
$default = self::$_icon;
foreach (\CRM_Eck_BAO_EckEntityType::getEntityTypes() as $entity_type) {
if ($entity_type['entity_name'] === $entityName) {
$default = $entity_type['icon'] ?? $default;
}
}
$record = civicrm_api4($entityName, 'get', [
'checkPermissions' => FALSE,
'select' => ['subtype:icon'],
'where' => [['id', '=', $entityId]],
], 0);
return $record['subtype:icon'] ?? $default;
}

}
8 changes: 8 additions & 0 deletions CRM/Eck/DAO/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/
class CRM_Eck_DAO_Entity extends CRM_Core_DAO {
const EXT = E::LONG_NAME;
jensschuppe marked this conversation as resolved.
Show resolved Hide resolved

private static $_entityType;

Expand All @@ -28,6 +29,13 @@ class CRM_Eck_DAO_Entity extends CRM_Core_DAO {

public static $_log = TRUE;

/**
* Icon associated with this entity.
*
* @var string
*/
public static $_icon = 'fa-cubes';

/**
* Paths for accessing this entity in the UI.
*
Expand Down
7 changes: 7 additions & 0 deletions eck.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ function eck_civicrm_post($action, $entity, $id, $object) {
// Flush navigation cache.
CRM_Core_BAO_Navigation::resetNavigation();
}
elseif (strpos($entity, 'Eck_') === 0 && in_array($action, ['create', 'edit'], TRUE)) {
jensschuppe marked this conversation as resolved.
Show resolved Hide resolved
// add the recently created Entity
\Civi\Api4\RecentItem::create()
->addValue('entity_type', $entity)
->addValue('entity_id', $id)
->execute();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<version>1.0-dev</version>
<develStage>dev</develStage>
<compatibility>
<ver>5.51</ver>
<ver>5.53</ver>
</compatibility>
<requires>
<ext>org.civicrm.afform</ext>
Expand Down
23 changes: 23 additions & 0 deletions managed/OptionValue_eck_recent_items.mgd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
// Auto-generate managed records for each entity type
$values = [];
foreach (CRM_Eck_BAO_EckEntityType::getEntityTypes() as $type) {
jensschuppe marked this conversation as resolved.
Show resolved Hide resolved
$values[] = [
'name' => 'recent_items_providers:' . $type['name'],
'entity' => 'OptionValue',
'cleanup' => 'always',
'update' => 'always',
'params' => [
'version' => 4,
'values' => [
'option_group_id.name' => 'recent_items_providers',
'label' => $type['label'],
'value' => $type['entity_name'],
'name' => $type['entity_name'],
'is_reserved' => TRUE,
'is_active' => TRUE,
],
],
];
}
return $values;