From bbaf36c737a48029e39e2c8da335729c78dee579 Mon Sep 17 00:00:00 2001 From: drishu Date: Fri, 13 Jan 2023 09:43:44 +0200 Subject: [PATCH 1/2] OEL-1574: Enable oebt version of slim_select. --- oe_whitelabel.theme | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/oe_whitelabel.theme b/oe_whitelabel.theme index 4643d41de..e5322900a 100644 --- a/oe_whitelabel.theme +++ b/oe_whitelabel.theme @@ -184,3 +184,59 @@ function oe_whitelabel_preprocess_media__document__default(&$variables) { $variables['translations'][] = $wrapper->toFileValueObject(); } } + +/** + * Implements hook_element_info_alter(). + */ +function oe_whitelabel_element_info_alter(array &$info): void { + $module_handler = \Drupal::service('module_handler'); + + if (isset($info['select']) && $module_handler->moduleExists('slim_select')) { + $info['select']['#process'][] = '_oe_whitelabel_process_element_select'; + } +} + +/** + * Process callback for applying slim_select on elements. + * + * @param array $element + * The element to alter. + * + * @return array + * The altered element. + * + * @see oe_whitelabel_element_info_alter + */ +function _oe_whitelabel_process_element_select(array &$element): array { + if (!$element['#multiple']) { + return $element; + } + + $element['#attributes']['class'][] = 'multi-select'; + // Config is empty so that it uses the defaults. + $element['#slim_select'] = []; + + return $element; +} + +/** + * Implements hook_library_info_alter(). + */ +function oe_whitelabel_library_info_alter(array &$libraries, string $extension): void { + if ('slim_select' !== $extension) { + return; + } + + $theme_handler = \Drupal::service('theme_handler'); + $theme_path = $theme_handler->getTheme('oe_bootstrap_theme')->getPath(); + $path = '/' . $theme_path . '/assets/js/slimselect.min.js'; + + $libraries['slim.select']['js'] = [ + $path => [ + 'minified' => TRUE, + 'attributes' => [ + 'defer' => TRUE, + ], + ], + ]; +} From fe424565cffbae3b5e494bbac674e12dd277fa2a Mon Sep 17 00:00:00 2001 From: drishu Date: Thu, 26 Jan 2023 09:59:31 +0200 Subject: [PATCH 2/2] OEL-1574: Remove duplicate slim.select css. --- oe_whitelabel.theme | 2 ++ 1 file changed, 2 insertions(+) diff --git a/oe_whitelabel.theme b/oe_whitelabel.theme index e5322900a..82fb809da 100644 --- a/oe_whitelabel.theme +++ b/oe_whitelabel.theme @@ -239,4 +239,6 @@ function oe_whitelabel_library_info_alter(array &$libraries, string $extension): ], ], ]; + // The slim.select css is already present in the parent theme. + unset($libraries['slim.select']['css']); }