Afform - Allow picking icon
authorColeman Watts <coleman@civicrm.org>
Thu, 30 Jun 2022 18:50:56 +0000 (14:50 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 30 Jun 2022 18:50:56 +0000 (14:50 -0400)
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.

ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js
ext/afform/admin/ang/afGuiEditor/config-form.html
ext/afform/core/Civi/Api4/Afform.php
ext/afform/core/afform.php
ext/civigrant/ang/afsearchGrants.aff.json

index 18283b58a5d9f7116977eb2a8485f5bc78ee768e..e99e02c58ce8be88d4718e71de7deaf0f01bf741 100644 (file)
@@ -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 = {};
index cb49a6f4fbf286295fb0bcd9dc30409e5edcfdc6..ca85a02cb13460507b20c273f2309922c6eeeccf 100644 (file)
@@ -71,6 +71,9 @@
           <option value="block">{{:: ts('As Block') }}</option>
           <option value="tab">{{:: ts('As Tab') }}</option>
         </select>
+        <div class="form-group" ng-show="editor.afform.contact_summary === 'tab'">
+          <input required ng-model="editor.afform.icon" crm-ui-icon-picker class="form-control">
+        </div>
       </div>
       <p class="help-block">{{:: ts('Placement can be configured using the Contact Layout Editor.') }}</p>
     </div>
index 3c48e9ef0545396a5ff3429478188900b4e8a988..15d2aea8d8f2a06943dfd033b4ef1ea4bf328a31 100644 (file)
@@ -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',
         ],
index 898dd8c08e496f0ba16080678ab287fc18368efa..19f86de1ad57c929ac686fe759cb71cbd619869c 100644 (file)
@@ -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']);
     }
   }
 }
index 093d18d9f91bd2cbcc2c31e0c70dece46fd63f38..44b9ee3dcdd2b3219bcea1c312acbffe4d71266f 100644 (file)
@@ -2,6 +2,7 @@
     "type": "search",
     "title": "Grants",
     "contact_summary": "tab",
+    "icon": "fa-money",
     "server_route": "",
     "permission": "access CiviGrant"
 }