Same name and namespace in other branches
- 3.0.x src/Plugin/Field/FieldWidget/ColorFieldWidgetBase.php \Drupal\color_field\Plugin\Field\FieldWidget\ColorFieldWidgetBase::formElement()
5 methods override ColorFieldWidgetBase::formElement()
- ColorFieldWidgetBox::formElement dans src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetBox.php - ColorFieldWidgetDefault::formElement dans src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetDefault.php - ColorFieldWidgetGrid::formElement dans src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetGrid.php - ColorFieldWidgetHTML5::formElement dans src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetHTML5.php - ColorFieldWidgetSpectrum::formElement dans src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetSpectrum.php
Fichier
-
src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetBase.php, line 18
Classe
- ColorFieldWidgetBase
- Base class for color_field widgets.
Namespace
Drupal\color_field\Plugin\Field\FieldWidgetCode
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['#uid'] = Html::getUniqueId('color-field-' . $this->fieldDefinition
->getName());
// Prepare color.
$color = NULL;
if (isset($items[$delta]->color)) {
$color = $items[$delta]->color;
if (substr($color, 0, 1) !== '#') {
$color = '#' . $color;
}
}
$input = [
'#type' => 'textfield',
'#maxlength' => 7,
'#size' => 7,
'#required' => $element['#required'],
'#default_value' => $color,
];
if ($this->getFieldSetting('opacity')) {
$element['color'] = $input;
$element['color']['#title'] = $this->t('Color');
$element['color']['#error_no_message'] = TRUE;
$element['#type'] = 'fieldset';
$element['opacity'] = [
'#title' => $this->t('Opacity'),
'#type' => 'number',
'#min' => 0,
'#max' => 1,
'#step' => 0.01,
'#required' => $element['#required'],
'#default_value' => isset($items[$delta]->opacity) ? $items[$delta]->opacity : NULL,
'#placeholder' => $this->getSetting('placeholder_opacity'),
'#error_no_message' => TRUE,
];
}
else {
$element['color'] = $element + $input;
$element['#type'] = 'container';
// Add a null field for opacity. Ths is required to accurately/detect
// changes in translations under some circumstances.
$element['opacity'] = [
'#type' => 'value',
'#value' => NULL,
];
}
return $element;
}