public function ColorFieldWidgetBox::settingsColorValidate in Color Field 8.2
Use element validator to make sure that hex values are in correct format.
Parameters
array $element: The Default colors element.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetBox.php, line 61
Class
- ColorFieldWidgetBox
- Plugin implementation of the color_field box widget.
Namespace
Drupal\color_field\Plugin\Field\FieldWidgetCode
public function settingsColorValidate(array $element, FormStateInterface $form_state) {
$default_colors = $form_state
->getValue($element['#parents']);
$colors = '';
if (!empty($default_colors)) {
preg_match_all("/#[0-9a-f]{6}/i", $default_colors, $default_colors, PREG_SET_ORDER);
foreach ($default_colors as $color) {
if (!empty($colors)) {
$colors .= ',';
}
$colors .= strtolower($color[0]);
}
}
$form_state
->setValue($element['#parents'], $colors);
}