From 4f55a79763bec5daa234cb9acb1aa8b3aff065e9 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 11 Jul 2019 10:07:13 -0400 Subject: [PATCH] Use select2 to display field mappings --- CRM/Core/BAO/Mapping.php | 20 ++++++++++++++++---- CRM/Export/Form/Select.php | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index d740ce2a27..0f5be86454 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -106,17 +106,20 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { } /** - * Get the list of mappings. + * Get the list of mappings for a select or select2 element. * * @param string $mappingType * Mapping type name. + * @param bool $select2 + * Format for select2 * * @return array * Array of mapping names, keyed by id. */ - public static function getMappings($mappingType) { + public static function getMappings($mappingType, $select2 = FALSE) { $result = civicrm_api3('Mapping', 'get', [ 'mapping_type_id' => $mappingType, + 'return' => ['name', 'description'], 'options' => [ 'sort' => 'name', 'limit' => 0, @@ -124,8 +127,17 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { ]); $mapping = []; - foreach ($result['values'] as $key => $value) { - $mapping[$key] = $value['name']; + foreach ($result['values'] as $id => $value) { + if ($select2) { + $item = ['id' => $id, 'text' => $value['name']]; + if (!empty($value['description'])) { + $item['description'] = $value['description']; + } + $mapping[] = $item; + } + else { + $mapping[$id] = $value['name']; + } } return $mapping; } diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php index 315c622cb1..c2a97d0acb 100644 --- a/CRM/Export/Form/Select.php +++ b/CRM/Export/Form/Select.php @@ -466,9 +466,9 @@ FROM {$this->_componentTable} $this->set('mappingTypeId', CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Mapping', 'mapping_type_id', $exportType)); - $mappings = CRM_Core_BAO_Mapping::getMappings($exportType); + $mappings = CRM_Core_BAO_Mapping::getMappings($exportType, TRUE); if (!empty($mappings)) { - $this->add('select', 'mapping', ts('Use Saved Field Mapping'), ['' => '-select-'] + $mappings); + $this->add('select2', 'mapping', ts('Use Saved Field Mapping'), $mappings, FALSE, ['placeholder' => ts('- select -')]); } } -- 2.25.1