function improved_multi_select_page_attachments in Improved Multi Select 8
Implements hook_page_attachments().
File
- ./
improved_multi_select.module, line 13 - Replace the default multi-select boxes with two panels list and filter.
Code
function improved_multi_select_page_attachments(&$attachments) {
$activated = FALSE;
$config = \Drupal::config('improved_multi_select.settings');
$context = [
'url' => trim($config
->get('url')),
'request_path' => \Drupal::request()
->getRequestUri(),
'selectors' => array_filter(explode("\n", str_replace("\r", "\n", trim($config
->get('selectors'))))),
];
// Activated on replace all option.
if ($replace_all = $config
->get('isall')) {
$activated = TRUE;
}
elseif ($context['url'] && \Drupal::service('path.matcher')
->matchPath($context['request_path'], $context['url']) || $context['selectors']) {
$activated = TRUE;
}
// Allow other modules to activate/deactivate the module for specific pages.
\Drupal::moduleHandler()
->alter('improved_multi_select_activated', $activated, $context);
if (!$activated) {
return;
}
$drupal_settings = [
'selectors' => improved_multi_select_load_selectors($replace_all, $context['selectors']),
'filtertype' => $config
->get('filtertype'),
'placeholder_text' => $config
->get('placeholder_text'),
'orderable' => $config
->get('orderable'),
'js_regex' => $config
->get('js_regex'),
'groupresetfilter' => $config
->get('groupresetfilter'),
'remove_required_attr' => $config
->get('remove_required_attr'),
'buttontext_add' => $config
->get('buttontext_add'),
'buttontext_addall' => $config
->get('buttontext_addall'),
'buttontext_del' => $config
->get('buttontext_del'),
'buttontext_delall' => $config
->get('buttontext_delall'),
'buttontext_moveup' => $config
->get('buttontext_moveup'),
'buttontext_movedown' => $config
->get('buttontext_movedown'),
];
// Allow other modules to alter our data.
\Drupal::moduleHandler()
->alter('improved_multi_select_attached', $drupal_settings, $context);
$attachments['#attached']['library'][] = 'improved_multi_select/ims';
$attachments['#attached']['drupalSettings']['improved_multi_select'] = $drupal_settings;
}