LanguageSelectMenuWidget.php in Flags 8
File
flags_language/src/Plugin/Field/FieldWidget/LanguageSelectMenuWidget.php
View source
<?php
namespace Drupal\flags_language\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldWidget\LanguageSelectWidget;
use Drupal\Core\Form\FormStateInterface;
class LanguageSelectMenuWidget extends LanguageSelectWidget {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$element['value'] = language_process_language_select($element['value']);
$element['value']['#type'] = 'select_icons';
$mapper = \Drupal::service('flags.mapping.language');
$element['value']['#options_attributes'] = $mapper
->getOptionAttributes(array_keys($element['value']['#options']));
$element['value']['#attached'] = array(
'library' => array(
'flags/flags',
),
);
return $element;
}
}