From 11b9f280dfce28fd693cb1fa05c6f420c586f185 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 8 Apr 2019 13:18:41 -0400 Subject: [PATCH] Navigation admin - fix icon picker & use select2 --- CRM/Admin/Form/Navigation.php | 10 +++++++--- CRM/Core/Form.php | 2 +- templates/CRM/Admin/Form/Navigation.tpl | 7 +------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CRM/Admin/Form/Navigation.php b/CRM/Admin/Form/Navigation.php index cf885742b5..1d7ae860cb 100644 --- a/CRM/Admin/Form/Navigation.php +++ b/CRM/Admin/Form/Navigation.php @@ -73,10 +73,10 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form { $permissions = []; foreach (CRM_Core_Permission::basicPermissions(TRUE, TRUE) as $id => $vals) { - $permissions[] = ['id' => $id, 'label' => $vals[0], 'description' => (array) CRM_Utils_Array::value(1, $vals)]; + $permissions[] = ['id' => $id, 'text' => $vals[0], 'description' => (array) CRM_Utils_Array::value(1, $vals)]; } - $this->add('text', 'permission', ts('Permission'), - ['placeholder' => ts('Unrestricted'), 'class' => 'huge', 'data-select-params' => json_encode(['data' => ['results' => $permissions, 'text' => 'label']])] + $this->add('select2', 'permission', ts('Permission'), $permissions, FALSE, + ['placeholder' => ts('Unrestricted'), 'class' => 'huge', 'multiple' => TRUE] ); $operators = ['AND' => ts('AND'), 'OR' => ts('OR')]; @@ -123,6 +123,10 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form { // its ok if there is no element called is_active $defaults['is_active'] = ($this->_id) ? $this->_defaults['is_active'] : 1; + if (!empty($defaults['icon'])) { + $defaults['icon'] = trim(str_replace('crm-i', '', $defaults['icon'])); + } + return $defaults; } diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index e6ecef99e4..df614d75e9 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -389,7 +389,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { if ($inputType == 'select2') { $type = 'text'; $options = $attributes; - $attributes = $attributes = ($extra ? $extra : []) + ['class' => '']; + $attributes = ($extra ? $extra : []) + ['class' => '']; $attributes['class'] = ltrim($attributes['class'] . " crm-select2 crm-form-select2"); $attributes['data-select-params'] = json_encode(['data' => $options, 'multiple' => !empty($attributes['multiple'])]); unset($attributes['multiple']); diff --git a/templates/CRM/Admin/Form/Navigation.tpl b/templates/CRM/Admin/Form/Navigation.tpl index 7ba9bc12ee..41a6e60115 100644 --- a/templates/CRM/Admin/Form/Navigation.tpl +++ b/templates/CRM/Admin/Form/Navigation.tpl @@ -66,12 +66,7 @@ .on('change', function() { $('span.permission_operator_wrapper').toggle(CRM._.includes($(this).val(), ',')); }) - .change() - .crmSelect2({ - formatResult: CRM.utils.formatSelect2Result, - formatSelection: function(row) {return row.label}, - multiple: true - }); + .change(); }); {/literal} -- 2.25.1