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

Add icons to multi-valued custom groups and display on contact tab #17531

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion CRM/Contact/Page/View/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
23 changes: 22 additions & 1 deletion CRM/Core/DAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/CustomGroup.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:db4bf2393a66e6df5ec2a504b2cf6b3d)
* (GenCodeChecksum:4c79528589c88a45d81a037f990077b7)
*/

/**
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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']);
}
Expand Down
4 changes: 4 additions & 0 deletions CRM/Custom/Form/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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'));

Expand Down
26 changes: 10 additions & 16 deletions CRM/Upgrade/Incremental/php/FiveTwentyEight.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
3 changes: 2 additions & 1 deletion Civi/Api4/Action/Entity/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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']);
Expand Down
12 changes: 9 additions & 3 deletions templates/CRM/Custom/Form/Group.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<td class="label">{$form.style.label}</td>
<td>{$form.style.html} {help id="id-display_style"}</td>
</tr>
<tr id="icon_row" class="hiddenElement">
<td class="label">{$form.icon.label}</td>
<td>{$form.icon.html}</td>
</tr>
<tr class="html-adjust">
<td>&nbsp;</td>
<td>{$form.collapse_display.html} {$form.collapse_display.label} {help id="id-collapse"}</td>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
Expand Down
9 changes: 9 additions & 0 deletions xml/schema/Core/CustomGroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,13 @@
<comment>Is this property public?</comment>
<add>4.7</add>
</field>
<field>
<name>icon</name>
<title>Icon</title>
<type>varchar</type>
<length>255</length>
<default>NULL</default>
<comment>crm-i icon class</comment>
<add>5.28</add>
</field>
</table>