From 2af065255602789512ac42ba751fd19c56311145 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 6 Jun 2020 22:07:23 -0400 Subject: [PATCH] Add icons to multi-valued custom groups and display on contact tab --- CRM/Contact/Page/View/Summary.php | 2 +- CRM/Core/BAO/CustomGroup.php | 2 ++ CRM/Core/DAO/CustomGroup.php | 23 +++++++++++++++- CRM/Custom/Form/Group.php | 4 +++ .../Incremental/php/FiveTwentyEight.php | 26 +++++++------------ Civi/Api4/Action/Entity/Get.php | 3 ++- templates/CRM/Custom/Form/Group.tpl | 12 ++++++--- xml/schema/Core/CustomGroup.xml | 9 +++++++ 8 files changed, 59 insertions(+), 22 deletions(-) diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index 7861eb149182..a9f61ee85c27 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -420,7 +420,7 @@ public function getTabs() { 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']), 'hideCount' => !$group['is_multiple'], 'class' => 'livePage', - 'icon' => 'crm-i fa-gear', + 'icon' => 'crm-i ' . ($group['icon'] ?: 'fa-gear'), ]; $weight += 10; } diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 0f08b2779845..fa57ff1561b8 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -106,6 +106,7 @@ public static function create(&$params) { 'help_post', 'is_active', 'is_multiple', + 'icon', ]; $current_db_version = CRM_Core_DAO::singleValueQuery("SELECT version FROM civicrm_domain WHERE id = " . CRM_Core_Config::domainID()); $is_public_version = $current_db_version >= '4.7.19' ? 1 : 0; @@ -1096,6 +1097,7 @@ public static function &getActiveGroups($entityType, $path, $cidToken = '%%cid%% $group['extra'] = ['gid' => $customGroupDAO->id]; $group['table_name'] = $customGroupDAO->table_name; $group['is_multiple'] = $customGroupDAO->is_multiple; + $group['icon'] = $customGroupDAO->icon; $groups[] = $group; } diff --git a/CRM/Core/DAO/CustomGroup.php b/CRM/Core/DAO/CustomGroup.php index 9ba24eeacf61..3896c204fefe 100644 --- a/CRM/Core/DAO/CustomGroup.php +++ b/CRM/Core/DAO/CustomGroup.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/CustomGroup.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:db4bf2393a66e6df5ec2a504b2cf6b3d) + * (GenCodeChecksum:4c79528589c88a45d81a037f990077b7) */ /** @@ -175,6 +175,13 @@ class CRM_Core_DAO_CustomGroup extends CRM_Core_DAO { */ public $is_public; + /** + * crm-i icon class + * + * @var string + */ + public $icon; + /** * Class constructor. */ @@ -493,6 +500,20 @@ public static function &fields() { 'bao' => 'CRM_Core_BAO_CustomGroup', 'localizable' => 0, ], + 'icon' => [ + 'name' => 'icon', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Icon'), + 'description' => ts('crm-i icon class'), + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'where' => 'civicrm_custom_group.icon', + 'default' => 'NULL', + 'table_name' => 'civicrm_custom_group', + 'entity' => 'CustomGroup', + 'bao' => 'CRM_Core_BAO_CustomGroup', + 'localizable' => 0, + ], ]; CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } diff --git a/CRM/Custom/Form/Group.php b/CRM/Custom/Form/Group.php index 10c582c32053..74d7a2e35848 100644 --- a/CRM/Custom/Form/Group.php +++ b/CRM/Custom/Form/Group.php @@ -50,6 +50,8 @@ class CRM_Custom_Form_Group extends CRM_Core_Form { * @return void */ public function preProcess() { + Civi::resources()->addScriptFile('civicrm', 'js/jquery/jquery.crmIconPicker.js'); + // current set id $this->_id = $this->get('id'); @@ -297,6 +299,8 @@ public function buildQuickForm() { // display style $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle()); + $this->add('text', 'icon', ts('Tab icon'), ['class' => 'crm-icon-picker', 'allowClear' => TRUE]); + // is this set collapsed or expanded ? $this->addElement('advcheckbox', 'collapse_display', ts('Collapse this set on initial display')); diff --git a/CRM/Upgrade/Incremental/php/FiveTwentyEight.php b/CRM/Upgrade/Incremental/php/FiveTwentyEight.php index 0526a39564ac..46667f025a89 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwentyEight.php +++ b/CRM/Upgrade/Incremental/php/FiveTwentyEight.php @@ -52,21 +52,15 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { * (change the x in the function name): */ - // /** - // * Upgrade function. - // * - // * @param string $rev - // */ - // public function upgrade_5_0_x($rev) { - // $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); - // $this->addTask('Do the foo change', 'taskFoo', ...); - // // Additional tasks here... - // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex. - // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable. - // } - - // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) { - // return TRUE; - // } + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_5_28_alpha1($rev) { + $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask('Add icon column to civicrm_custom_group', 'addColumn', + 'civicrm_custom_group', 'icon', "varchar(255) COMMENT 'crm-i icon class' DEFAULT NULL"); + } } diff --git a/Civi/Api4/Action/Entity/Get.php b/Civi/Api4/Action/Entity/Get.php index e041844ca8bb..044105e4e5a6 100644 --- a/Civi/Api4/Action/Entity/Get.php +++ b/Civi/Api4/Action/Entity/Get.php @@ -86,7 +86,7 @@ private function addCustomEntities(&$entities) { $customEntities = CustomGroup::get() ->addWhere('is_multiple', '=', 1) ->addWhere('is_active', '=', 1) - ->setSelect(['name', 'title', 'help_pre', 'help_post', 'extends']) + ->setSelect(['name', 'title', 'help_pre', 'help_post', 'extends', 'icon']) ->setCheckPermissions(FALSE) ->execute(); foreach ($customEntities as $customEntity) { @@ -99,6 +99,7 @@ private function addCustomEntities(&$entities) { 'https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/#multiple-record-fieldsets', '\\Civi\\Api4\\CustomGroup', ], + 'icon' => $customEntity['icon'], ]; if (!empty($customEntity['help_pre'])) { $entities[$fieldName]['comment'] = $this->plainTextify($customEntity['help_pre']); diff --git a/templates/CRM/Custom/Form/Group.tpl b/templates/CRM/Custom/Form/Group.tpl index 086864b2bdbe..c371d06f9b70 100644 --- a/templates/CRM/Custom/Form/Group.tpl +++ b/templates/CRM/Custom/Form/Group.tpl @@ -36,6 +36,10 @@ {$form.style.label} {$form.style.html} {help id="id-display_style"} + + {$form.icon.label} + {$form.icon.html} +   {$form.collapse_display.html} {$form.collapse_display.label} {help id="id-collapse"} @@ -88,7 +92,9 @@ CRM.$(function($) { if ($(this).val() == 'Tab') { $('#collapse_display').prop('checked', false); } + $('#icon_row').toggle($(this).val() !== 'Inline'); }); + $('#icon_row').toggle($("select#style").val() !== 'Inline'); /** * Check if this is a contact-related set and show/hide other options accordingly @@ -138,12 +144,12 @@ CRM.$(function($) { $("tr#multiple_row").show(); if (onFormLoad !== true) { $('#collapse_display').prop('checked', false); - $("select#style").append(tabWithTableOption); - $("select#style").val('Tab with table'); + $("select#style").append(tabWithTableOption).val('Tab with table'); } + $('#icon_row').toggle($("select#style").val() !== 'Inline'); } else { - $("tr#multiple_row").hide(); + $("tr#multiple_row, #icon_row").hide(); if ($("select#style").val() === 'Tab with table') { $("select#style").val('Inline'); } diff --git a/xml/schema/Core/CustomGroup.xml b/xml/schema/Core/CustomGroup.xml index 1f64dc3b8365..e0f424ddfc49 100644 --- a/xml/schema/Core/CustomGroup.xml +++ b/xml/schema/Core/CustomGroup.xml @@ -231,4 +231,13 @@ Is this property public? 4.7 + + icon + Icon + varchar + 255 + NULL + crm-i icon class + 5.28 +