function select2boxes_field_widget_form_alter in Select2 Boxes 8
Implements hook_field_widget_form_alter().
File
- ./
select2boxes.module, line 179 - Basic module file.
Code
function select2boxes_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
/** @var \Drupal\Core\Field\WidgetInterface $plugin */
$plugin = $context['widget'];
/** @var \Drupal\Core\Field\FieldItemList $items */
$items = $context['items'];
if (in_array($plugin
->getPluginId(), _select2boxes_address_widgets_list())) {
$settings = $plugin
->getThirdPartySettings('select2boxes');
if (!empty($settings['enable_select2'])) {
// Put all field names with enabled Select2 option to the drupalSettings
// to allow Drupal's JS behavior handle it.
$element['#attached']['library'][] = 'select2boxes/widget';
$element['#attached']['drupalSettings']['addressFieldsSelect2'][$items
->getName()] = TRUE;
}
}
}