From: Coleman Watts Date: Tue, 2 Feb 2021 03:32:11 +0000 (-0500) Subject: Afform Admin - Pluralize tabs & rename variable with same name as another X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3d371a033451fc7efc1e63c669db717c207c9892;p=civicrm-core.git Afform Admin - Pluralize tabs & rename variable with same name as another --- diff --git a/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php b/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php index 782a5fcc71..468d690bdb 100644 --- a/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php +++ b/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php @@ -10,13 +10,24 @@ class AfformAdminMeta { * @return array */ public static function getAdminSettings() { + $afformTypes = (array) \Civi\Api4\OptionValue::get(FALSE) + ->addSelect('name', 'label', 'icon') + ->addWhere('is_active', '=', TRUE) + ->addWhere('option_group_id:name', '=', 'afform_type') + ->addOrderBy('weight', 'ASC') + ->execute(); + // Pluralize tabs (too bad option groups only store a single label) + $plurals = [ + 'form' => ts('Custom Forms'), + 'search' => ts('Search Displays'), + 'block' => ts('Field Blocks'), + 'system' => ts('System Forms'), + ]; + foreach ($afformTypes as $index => $type) { + $afformTypes[$index]['plural'] = $plurals[$type['name']] ?? \CRM_Utils_String::pluralize($type['label']); + } return [ - 'afform_type' => \Civi\Api4\OptionValue::get(FALSE) - ->addSelect('name', 'label', 'icon') - ->addWhere('is_active', '=', TRUE) - ->addWhere('option_group_id:name', '=', 'afform_type') - ->addOrderBy('weight', 'ASC') - ->execute(), + 'afform_type' => $afformTypes, ]; } diff --git a/ext/afform/admin/ang/afAdmin/afAdminList.controller.js b/ext/afform/admin/ang/afAdmin/afAdminList.controller.js index f1d8003439..716e7900db 100644 --- a/ext/afform/admin/ang/afAdmin/afAdminList.controller.js +++ b/ext/afform/admin/ang/afAdmin/afAdminList.controller.js @@ -8,12 +8,12 @@ $scope.crmUrl = CRM.url; this.tabs = CRM.afAdmin.afform_type; - $scope.tabs = _.indexBy(ctrl.tabs, 'name'); + $scope.types = _.indexBy(ctrl.tabs, 'name'); _.each(['form', 'block', 'search'], function(type) { - if ($scope.tabs[type]) { - $scope.tabs[type].options = []; + if ($scope.types[type]) { + $scope.types[type].options = []; if (type === 'form') { - $scope.tabs.form.default = '#create/form/Individual'; + $scope.types.form.default = '#create/form/Individual'; } } }); @@ -33,7 +33,7 @@ this.createLinks = function() { ctrl.searchCreateLinks = ''; - if ($scope.tabs[ctrl.tab].options.length) { + if ($scope.types[ctrl.tab].options.length) { return; } var links = []; @@ -48,7 +48,7 @@ }); } }); - $scope.tabs.form.options = _.sortBy(links, 'Label'); + $scope.types.form.options = _.sortBy(links, 'Label'); } if (ctrl.tab === 'block') { @@ -61,7 +61,7 @@ }); } }); - $scope.tabs.block.options = _.sortBy(links, 'Label'); + $scope.types.block.options = _.sortBy(links, 'Label'); } if (ctrl.tab === 'search') { @@ -75,7 +75,7 @@ icon: searchDisplay['type:icon'] }); }); - $scope.tabs.search.options = _.sortBy(links, 'Label'); + $scope.types.search.options = _.sortBy(links, 'Label'); }); } }; diff --git a/ext/afform/admin/ang/afAdmin/afAdminList.html b/ext/afform/admin/ang/afAdmin/afAdminList.html index 02dd53f96b..bebb59f91e 100644 --- a/ext/afform/admin/ang/afAdmin/afAdminList.html +++ b/ext/afform/admin/ang/afAdmin/afAdminList.html @@ -3,27 +3,27 @@
-
- - {{ ts('New %1', {1: tabs[$ctrl.tab].label }) }} +
+ + {{ ts('New %1', {1: types[$ctrl.tab].label }) }}