summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-02-13 17:04:35 (GMT)
committerAlex Pott2015-02-13 17:04:35 (GMT)
commitcd57d598a40f989e8bb69d41be351a0c0f9480ed (patch)
treebd45bd8b77aa792b674c16ccc98773b6c44e0cc5
parent584907e1ac3b0aeecad2d7eddc51d1aee9da408c (diff)
Issue #1906264 by mgifford, mitsuroseba, blueminds, johanv, claudiu.cristea, kattekrab, amitgoyal, sivaji@knackforge.com: Required alt tag missing on image alt tag input
-rw-r--r--core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php11
-rw-r--r--core/modules/image/src/Tests/ImageFieldValidateTest.php42
2 files changed, 44 insertions, 9 deletions
diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
index 7b16bd2..e2b6816 100644
--- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
+++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
@@ -233,6 +233,7 @@ class ImageWidget extends FileWidget {
'#maxlength' => 512,
'#weight' => -12,
'#access' => (bool) $item['fids'] && $element['#alt_field'],
+ '#required' => $element['#alt_field_required'],
'#element_validate' => $element['#alt_field_required'] == 1 ? array(array(get_called_class(), 'validateRequiredFields')) : array(),
);
$element['title'] = array(
@@ -243,6 +244,7 @@ class ImageWidget extends FileWidget {
'#maxlength' => 1024,
'#weight' => -11,
'#access' => (bool) $item['fids'] && $element['#title_field'],
+ '#required' => $element['#title_field_required'],
'#element_validate' => $element['#title_field_required'] == 1 ? array(array(get_called_class(), 'validateRequiredFields')) : array(),
);
@@ -268,13 +270,10 @@ class ImageWidget extends FileWidget {
if (!array_key_exists($field, $image_field)) {
return;
}
- // Check if field is left empty.
- elseif (empty($image_field[$field])) {
- $form_state->setError($element, t('The field !title is required', array('!title' => $element['#title'])));
- return;
- }
+ }
+ else {
+ $form_state->setLimitValidationErrors([]);
}
}
-
}
diff --git a/core/modules/image/src/Tests/ImageFieldValidateTest.php b/core/modules/image/src/Tests/ImageFieldValidateTest.php
index 025c65e..e6afc32 100644
--- a/core/modules/image/src/Tests/ImageFieldValidateTest.php
+++ b/core/modules/image/src/Tests/ImageFieldValidateTest.php
@@ -59,13 +59,49 @@ class ImageFieldValidateTest extends ImageFieldTestBase {
'alt_field_required' => 1,
'title_field' => 1,
'title_field_required' => 1,
+ 'required' => 1,
);
- $this->createImageField($field_name, 'article', array(), $field_settings);
+ $instance = $this->createImageField($field_name, 'article', array(), $field_settings);
$images = $this->drupalGetTestFiles('image');
// Let's just use the first image.
$image = $images[0];
$this->uploadNodeImage($image, $field_name, 'article');
- $this->assertText(t('The field Alternative text is required'), 'Node save failed when alt text required was set and alt text was left empty.');
- $this->assertText(t('The field Title is required'), 'Node save failed when title text required was set and title text was left empty.');
+
+ // Look for form-required for the alt text.
+ $elements = $this->xpath('//label[@for="edit-' . $field_name . '-0-alt" and @class="form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-alt"]');
+
+ $this->assertTrue(isset($elements[0]),'Required marker is shown for the required alt text.');
+
+ $elements = $this->xpath('//label[@for="edit-' . $field_name . '-0-title" and @class="form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-title"]');
+
+ $this->assertTrue(isset($elements[0]), 'Required marker is shown for the required title text.');
+
+ $this->assertText(t('Alternative text field is required.'));
+ $this->assertText(t('Title field is required.'));
+
+ $instance->settings['alt_field_required'] = 0;
+ $instance->settings['title_field_required'] = 0;
+ $instance->save();
+
+ $edit = array(
+ 'title[0][value]' => $this->randomMachineName(),
+ );
+ $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
+
+ $this->assertNoText(t('Alternative text field is required.'));
+ $this->assertNoText(t('Title field is required.'));
+
+ $instance->settings['required'] = 0;
+ $instance->settings['alt_field_required'] = 1;
+ $instance->settings['title_field_required'] = 1;
+ $instance->save();
+
+ $edit = array(
+ 'title[0][value]' => $this->randomMachineName(),
+ );
+ $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
+
+ $this->assertNoText(t('Alternative text field is required.'));
+ $this->assertNoText(t('Title field is required.'));
}
}