Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OEL-1574: Enable oebt version of slim_select. #205

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions oe_whitelabel.theme
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,61 @@ 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');
brummbar marked this conversation as resolved.
Show resolved Hide resolved

if (isset($info['select']) && $module_handler->moduleExists('slim_select')) {
$info['select']['#process'][] = '_oe_whitelabel_process_element_select';
brummbar marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* 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';
brummbar marked this conversation as resolved.
Show resolved Hide resolved
// 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,
],
],
];
// The slim.select css is already present in the parent theme.
unset($libraries['slim.select']['css']);
}