public function PictureMappingForm::validate in Picture 8
File
- src/
PictureMappingForm.php, line 96 - Contains Drupal\picture\PictureMappingForm.
Class
- PictureMappingForm
- Form controller for the responsive image edit/add forms.
Namespace
Drupal\pictureCode
public function validate(array $form, FormStateInterface $form_state) {
parent::validate($form, $form_state);
// Only validate on edit.
if ($form_state
->hasValue('keyed_styles')) {
$styles = $form_state
->getValue('keyed_styles');
foreach ($styles as $breakpoint_id => $multiplier_styles) {
foreach ($multiplier_styles as $multiplier => $style) {
if ($style['image_mapping_type'] == 'sizes') {
$form_state
->setValue(array(
'keyed_styles',
$breakpoint_id,
$multiplier,
'image_mapping',
), array(
'sizes_image_styles' => array_filter($style['sizes_image_styles']),
'sizes' => $style['sizes'],
));
}
elseif ($style['image_mapping_type'] != 'image_style') {
$form_state
->unsetValue(array(
'keyed_styles',
$breakpoint_id,
$multiplier,
));
}
$form_state
->unsetValue(array(
'keyed_styles',
$breakpoint_id,
$multiplier,
'sizes_image_styles',
));
$form_state
->unsetValue(array(
'keyed_styles',
$breakpoint_id,
$multiplier,
'sizes',
));
}
}
}
}