From 34c92b2c104bb07b393618de4f1845d763666ecb Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 30 Jun 2022 14:50:56 -0400 Subject: [PATCH] Afform - Allow picking icon Allows afforms placed as a contact summary tab to specify an icon. It also switches Afforms's hook_civicrm_tabset to use the API, which ensures virtual forms get picked up. Adds the new icon for CiviGrant as an example. --- .../ang/afGuiEditor/afGuiEditor.component.js | 1 + .../admin/ang/afGuiEditor/config-form.html | 3 ++ ext/afform/core/Civi/Api4/Afform.php | 4 +++ ext/afform/core/afform.php | 36 +++++++++---------- ext/civigrant/ang/afsearchGrants.aff.json | 1 + 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js index 18283b58a5..e99e02c58c 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js @@ -95,6 +95,7 @@ editor.afform.is_dashlet = false; editor.afform.title += ' ' + ts('(copy)'); } + editor.afform.icon = editor.afform.icon || 'fa-list-alt'; $scope.canvasTab = 'layout'; $scope.layoutHtml = ''; $scope.entities = {}; diff --git a/ext/afform/admin/ang/afGuiEditor/config-form.html b/ext/afform/admin/ang/afGuiEditor/config-form.html index cb49a6f4fb..ca85a02cb1 100644 --- a/ext/afform/admin/ang/afGuiEditor/config-form.html +++ b/ext/afform/admin/ang/afGuiEditor/config-form.html @@ -71,6 +71,9 @@ +
+ +

{{:: ts('Placement can be configured using the Contact Layout Editor.') }}

diff --git a/ext/afform/core/Civi/Api4/Afform.php b/ext/afform/core/Civi/Api4/Afform.php index 3c48e9ef05..15d2aea8d8 100644 --- a/ext/afform/core/Civi/Api4/Afform.php +++ b/ext/afform/core/Civi/Api4/Afform.php @@ -165,6 +165,10 @@ class Afform extends Generic\AbstractEntity { 'tab' => ts('Contact Summary Tab'), ], ], + [ + 'name' => 'icon', + 'description' => 'Icon shown in the contact summary tab', + ], [ 'name' => 'server_route', ], diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 898dd8c08e..19f86de1ad 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -178,25 +178,25 @@ function afform_civicrm_tabset($tabsetName, &$tabs, $context) { if ($tabsetName !== 'civicrm/contact/view') { return; } - $scanner = \Civi::service('afform_scanner'); + $afforms = Civi\Api4\Afform::get(FALSE) + ->addWhere('contact_summary', '=', 'tab') + ->addSelect('name', 'title', 'icon', 'module_name', 'directive_name') + ->execute(); $weight = 111; - foreach ($scanner->getMetas() as $afform) { - if (!empty($afform['contact_summary']) && $afform['contact_summary'] === 'tab') { - $module = _afform_angular_module_name($afform['name']); - $tabs[] = [ - 'id' => $afform['name'], - 'title' => $afform['title'], - 'weight' => $weight++, - 'icon' => 'crm-i fa-list-alt', - 'is_active' => TRUE, - 'template' => 'afform/contactSummary/AfformTab.tpl', - 'module' => $module, - 'directive' => _afform_angular_module_name($afform['name'], 'dash'), - ]; - // If this is the real contact summary page (and not a callback from ContactLayoutEditor), load module. - if (empty($context['caller'])) { - Civi::service('angularjs.loader')->addModules($module); - } + foreach ($afforms as $afform) { + $tabs[] = [ + 'id' => $afform['name'], + 'title' => $afform['title'], + 'weight' => $weight++, + 'icon' => 'crm-i ' . ($afform['icon'] ?: 'fa-list-alt'), + 'is_active' => TRUE, + 'template' => 'afform/contactSummary/AfformTab.tpl', + 'module' => $afform['module_name'], + 'directive' => $afform['directive_name'], + ]; + // If this is the real contact summary page (and not a callback from ContactLayoutEditor), load module. + if (empty($context['caller'])) { + Civi::service('angularjs.loader')->addModules($afform['module_name']); } } } diff --git a/ext/civigrant/ang/afsearchGrants.aff.json b/ext/civigrant/ang/afsearchGrants.aff.json index 093d18d9f9..44b9ee3dcd 100644 --- a/ext/civigrant/ang/afsearchGrants.aff.json +++ b/ext/civigrant/ang/afsearchGrants.aff.json @@ -2,6 +2,7 @@ "type": "search", "title": "Grants", "contact_summary": "tab", + "icon": "fa-money", "server_route": "", "permission": "access CiviGrant" } -- 2.25.1