From 79a5aecbdb54187b25df3f9a534da175ba175d90 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 9 Mar 2022 13:21:12 +0100 Subject: [PATCH] Allow adding tags to ECK entities --- CRM/Eck/Page/Entity/TabHeader.php | 8 ++++ CRM/Eck/Page/Entity/Tag.php | 67 +++++++++++++++++++++++++++ eck.php | 20 ++++++++ templates/CRM/Eck/Page/Entity/Tag.tpl | 17 +++++++ xml/Menu/eck.xml | 6 +++ 5 files changed, 118 insertions(+) create mode 100644 CRM/Eck/Page/Entity/Tag.php create mode 100644 templates/CRM/Eck/Page/Entity/Tag.tpl diff --git a/CRM/Eck/Page/Entity/TabHeader.php b/CRM/Eck/Page/Entity/TabHeader.php index 95a5ec4..eae204e 100644 --- a/CRM/Eck/Page/Entity/TabHeader.php +++ b/CRM/Eck/Page/Entity/TabHeader.php @@ -96,6 +96,14 @@ public static function process(&$page) { ] + $default; Civi::service('angularjs.loader')->addModules($module); + $tabs['tags'] = [ + 'title' => ts('Tags'), + 'link' => CRM_Utils_System::url( + 'civicrm/eck/entity/tag', + "reset=1&type={$entityType['name']}&id={$entityID}" + ), + ] + $default; + // see if any other modules want to add any tabs // note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation. CRM_Utils_Hook::tabset( diff --git a/CRM/Eck/Page/Entity/Tag.php b/CRM/Eck/Page/Entity/Tag.php new file mode 100644 index 0000000..3ecd594 --- /dev/null +++ b/CRM/Eck/Page/Entity/Tag.php @@ -0,0 +1,67 @@ +_action); + $controller->setEmbedded(TRUE); + $controller->reset(); + $controller->set('entityTable', $entity_types[$this->_entityType]['table_name']); + $controller->set('entityID', $this->_entityId); + $controller->process(); + $controller->run(); + } + + public function preProcess() { + $this->_entityType = CRM_Utils_Request::retrieve('type', 'String', $this, TRUE); + $this->_entityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); + $this->assign('entityType', $this->_entityType); + $this->assign('entityId', $this->_entityId); + + /** + * TODO: + * Check permission for editing ECK entity tags. + * @see CRM_Contact_Page_View::checkUserPermission() + * For now, allow editing for all users. + */ + $this->assign('permission', 'edit'); + + $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); + $this->assign('action', $this->_action); + } + + /** + * the main function that is called when the page loads + * it decides the which action has to be taken for the page. + * + * @return null + */ + public function run() { + $this->preProcess(); + + $this->browse(); + + return parent::run(); + } + +} diff --git a/eck.php b/eck.php index ccb55f5..465eaaa 100644 --- a/eck.php +++ b/eck.php @@ -71,6 +71,26 @@ function eck_civicrm_managed(&$entities, $modules = NULL) { ], ], ]; + $entities[] = [ + 'module' => E::LONG_NAME, + 'name' => 'tag_used_for:' . $type['name'], + 'entity' => 'OptionValue', + 'cleanup' => 'always', + 'update' => 'always', + 'params' => [ + 'version' => 4, + 'values' => [ + 'option_group_id.name' => 'tag_used_for', + 'label' => $type['label'], + 'value' => $type['table_name'], + 'name' => $type['entity_name'], + 'description' => NULL, + 'is_reserved' => TRUE, + 'is_active' => TRUE, + 'grouping' => NULL, + ], + ], + ]; } } diff --git a/templates/CRM/Eck/Page/Entity/Tag.tpl b/templates/CRM/Eck/Page/Entity/Tag.tpl new file mode 100644 index 0000000..972635c --- /dev/null +++ b/templates/CRM/Eck/Page/Entity/Tag.tpl @@ -0,0 +1,17 @@ +{*-------------------------------------------------------+ +| CiviCRM Entity Construction Kit | +| Copyright (C) 2022 SYSTOPIA | +| Author: J. Schuppe (schuppe@systopia.de) | ++--------------------------------------------------------+ +| This program is released as free software under the | +| Affero GPL license. You can redistribute it and/or | +| modify it under the terms of this license which you | +| can read by viewing the included agpl.txt or online | +| at www.gnu.org/licenses/agpl.html. Removal of this | +| copyright header is strictly prohibited without | +| written permission from the original author(s). | ++--------------------------------------------------------*} + +{crmScope extensionKey='de.systopia.eck'} + {include file="CRM/Tag/Form/Tag.tpl"} +{/crmScope} diff --git a/xml/Menu/eck.xml b/xml/Menu/eck.xml index 260b39d..2f3d2fc 100644 --- a/xml/Menu/eck.xml +++ b/xml/Menu/eck.xml @@ -38,4 +38,10 @@ Entity access CiviCRM + + civicrm/eck/entity/tag + CRM_Eck_Page_Entity_Tag + Entity Tags + access CiviCRM +