summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2015-09-30 21:24:28 (GMT)
committerwebchick2015-09-30 21:24:28 (GMT)
commit372394ead8ca9ff0f8735ff238d42cb4feae4c80 (patch)
tree4d31ff53d1e0a9140ab0e16df366608ff39f83fc
parentc63f02a12cd1d1dcc0cfce02d93e3bfec0afa694 (diff)
Issue #2481635 by attiks, mdrummond, Jelle_S: sizes is now mandatory in the spec
-rw-r--r--core/modules/responsive_image/src/ResponsiveImageStyleForm.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php
index 6fc982b..0d03835 100644
--- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php
+++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php
@@ -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.');
+ }
+ }
+ }
+ }
}
}