Commit cd57d598 authored by alexpott's avatar alexpott

Issue #1906264 by mgifford, mitsuroseba, blueminds, johanv, claudiu.cristea,...

Issue #1906264 by mgifford, mitsuroseba, blueminds, johanv, claudiu.cristea, kattekrab, amitgoyal, sivaji@knackforge.com: Required alt tag missing on image alt tag input
parent 584907e1
......@@ -233,6 +233,7 @@ public static function process($element, FormStateInterface $form_state, $form)
'#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 @@ public static function process($element, FormStateInterface $form_state, $form)
'#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 @@ public static function validateRequiredFields($element, FormStateInterface $form
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([]);
}
}
}
......@@ -59,13 +59,49 @@ function testRequiredAttributes() {
'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.'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment