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