Issue #2481635 by attiks, mdrummond, Jelle_S: sizes is now mandatory in the spec
parent
c63f02a12c
commit
372394ead8
|
@ -160,12 +160,15 @@ class ResponsiveImageStyleForm extends EntityForm {
|
|||
$form['keyed_styles'][$breakpoint_id][$multiplier]['sizes'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Sizes'),
|
||||
'#default_value' => isset($image_style_mapping['image_mapping']['sizes']) ? $image_style_mapping['image_mapping']['sizes'] : '',
|
||||
'#default_value' => isset($image_style_mapping['image_mapping']['sizes']) ? $image_style_mapping['image_mapping']['sizes'] : '100vw',
|
||||
'#description' => $this->t('Enter the value for the sizes attribute: for example "(min-width:700px) 700px, 100vw)".'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes'),
|
||||
),
|
||||
'required' => array(
|
||||
':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes'),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['keyed_styles'][$breakpoint_id][$multiplier]['sizes_image_styles'] = array(
|
||||
|
@ -178,6 +181,9 @@ class ResponsiveImageStyleForm extends EntityForm {
|
|||
'visible' => array(
|
||||
':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes'),
|
||||
),
|
||||
'required' => array(
|
||||
':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -221,6 +227,20 @@ class ResponsiveImageStyleForm extends EntityForm {
|
|||
// 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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue