public function ResponsiveImageStyleForm::validateForm in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/responsive_image/src/ResponsiveImageStyleForm.php \Drupal\responsive_image\ResponsiveImageStyleForm::validateForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- core/
modules/ responsive_image/ src/ ResponsiveImageStyleForm.php, line 222 - Contains \Drupal\responsive_image\ResponsiveImageStyleForm.
Class
- ResponsiveImageStyleForm
- Form controller for the responsive image edit/add forms.
Namespace
Drupal\responsive_imageCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// Only validate on edit.
if ($form_state
->hasValue('keyed_styles')) {
// Check if another breakpoint group is selected.
if ($form_state
->getValue('breakpoint_group') != $form_state
->getCompleteForm()['breakpoint_group']['#default_value']) {
// Remove the image style mappings since the breakpoint ID has changed.
$form_state
->unsetValue('keyed_styles');
}
// Check that at least 1 image style has been selected when using sizes.
foreach ($form_state
->getValue('keyed_styles') as $breakpoint_id => $multipliers) {
foreach ($multipliers as $multiplier => $image_style_mapping) {
if ($image_style_mapping['image_mapping_type'] === 'sizes') {
if (empty($image_style_mapping['sizes'])) {
$form_state
->setError($form['keyed_styles'][$breakpoint_id][$multiplier]['sizes'], 'Provide a value for the sizes attribute.');
}
if (empty(array_keys(array_filter($image_style_mapping['sizes_image_styles'])))) {
$form_state
->setError($form['keyed_styles'][$breakpoint_id][$multiplier]['sizes_image_styles'], 'Select at least one image style.');
}
}
}
}
}
}