Same name and namespace in other branches
- 8.x-2.x src/Plugin/Field/FieldWidget/ColorFieldWidgetGrid.php \Drupal\color_field\Plugin\Field\FieldWidget\ColorFieldWidgetGrid::formElement()
Overrides ColorFieldWidgetBase::formElement
File
-
src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetGrid.php, line 123
Class
- ColorFieldWidgetGrid
- Plugin implementation of the 'color_field_default' widget.
Namespace
Drupal\color_field\Plugin\Field\FieldWidgetCode
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) : array {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
// We are nesting some sub-elements inside the parent, so we need a wrapper.
// We also need to add another #title attribute at the top level for ease in
// identifying this item in error messages. We do not want to display this
// title because the actual title display is handled at a higher level by
// the Field module.
// $element['#theme_wrappers'] = array('color_field_widget_grid');.
$element['#attached']['library'][] = 'color_field/color-field-widget-grid';
// Set Drupal settings.
$settings = $this->getSettings();
$element['#attached']['drupalSettings']['color_field']['color_field_widget_grid'][$element['#uid']] = $settings;
$element['color']['#attributes']['class'][] = 'js-color-field-widget-grid__color';
$element['color']['#attributes']['id'] = $element['#uid'];
$element['color']['#wrapper_attributes']['class'][] = 'clearfix';
return $element;
}