class ColorPickerWidget
Same name in other branches
- 3.x modules/field_example/src/Plugin/Field/FieldWidget/ColorPickerWidget.php \Drupal\field_example\Plugin\Field\FieldWidget\ColorPickerWidget
- 4.0.x modules/field_example/src/Plugin/Field/FieldWidget/ColorPickerWidget.php \Drupal\field_example\Plugin\Field\FieldWidget\ColorPickerWidget
Plugin implementation of the 'field_example_colorpicker' widget.
Plugin annotation
@FieldWidget(
id = "field_example_colorpicker",
module = "field_example",
label = @Translation("Color Picker"),
field_types = {
"field_example_rgb"
}
)
Hierarchy
- class \Drupal\field_example\Plugin\Field\FieldWidget\TextWidget extends \Drupal\Core\Field\WidgetBase
- class \Drupal\field_example\Plugin\Field\FieldWidget\ColorPickerWidget extends \Drupal\field_example\Plugin\Field\FieldWidget\TextWidget
Expanded class hierarchy of ColorPickerWidget
File
-
field_example/
src/ Plugin/ Field/ FieldWidget/ ColorPickerWidget.php, line 20
Namespace
Drupal\field_example\Plugin\Field\FieldWidgetView source
class ColorPickerWidget extends TextWidget {
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$element['value'] += [
'#suffix' => '<div class="field-example-colorpicker"></div>',
'#attributes' => [
'class' => [
'edit-field-example-colorpicker',
],
],
'#attached' => [
// Add Farbtastic color picker and javascript file to trigger the
// colorpicker.
'library' => [
'core/jquery.farbtastic',
'field_example/colorpicker',
],
],
];
return $element;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ColorPickerWidget::formElement | public | function | Overrides TextWidget::formElement | |
TextWidget::validate | public | function | Validate the color text field. |