Commit 3f7d8f3d authored by oknate's avatar oknate Committed by Wim Leers

Issue #3060642 by oknate, Wim Leers, marcoscano: Follow-up for #2924391: how...

Issue #3060642 by oknate, Wim Leers, marcoscano: Follow-up for #2924391: how to remove override and revert back to the inherited/original metadata
parent 7c561fda
......@@ -118,8 +118,8 @@ class MediaImageDecorator implements EntityEmbedDisplayInterface {
$settings = $entity->{$image_field}->getItemDefinition()->getSettings();
$attributes = $this->getAttributeValues();
$alt = isset($attributes['alt']) ? $attributes['alt'] : $entity->{$image_field}->alt;
$title = isset($attributes['title']) ? $attributes['title'] : $entity->{$image_field}->title;
$alt = isset($attributes['alt']) ? $attributes['alt'] : NULL;
$title = isset($attributes['title']) ? $attributes['title'] : NULL;
// Setting empty alt to double quotes. See ImageFieldFormatter.
if ($settings['alt_field_required'] && $alt === '') {
......@@ -133,9 +133,9 @@ class MediaImageDecorator implements EntityEmbedDisplayInterface {
'#title' => $this->t('Alternate text'),
'#default_value' => $alt,
'#description' => $this->t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
'#required' => $settings['alt_field_required'],
'#required_error' => $this->t('Alternative text is required.<br />(Only in rare cases should this be left empty. To create empty alternative text, enter <code>""</code> — two double quotes without any content).'),
'#maxlength' => 512,
'#placeholder' => $entity->{$image_field}->alt,
];
}
......@@ -146,7 +146,7 @@ class MediaImageDecorator implements EntityEmbedDisplayInterface {
'#default_value' => $title,
'#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),
'#maxlength' => 1024,
'#required' => $settings['title_field_required'],
'#placeholder' => $entity->{$image_field}->title,
];
}
}
......
......@@ -196,10 +196,10 @@ class MediaImageTest extends EntityEmbedTestBase {
$this->assertSession()->assertWaitOnAjaxRequest();
$alt = $this->assertSession()
->fieldExists('attributes[data-entity-embed-display-settings][alt]');
$this->assertEquals($this->media->field_media_image->alt, $alt->getValue());
$this->assertEquals($this->media->field_media_image->alt, $alt->getAttribute('placeholder'));
$title = $this->assertSession()
->fieldExists('attributes[data-entity-embed-display-settings][title]');
$this->assertEquals($this->media->field_media_image->title, $title->getValue());
$this->assertEquals($this->media->field_media_image->title, $title->getAttribute('placeholder'));
$this->submitDialog();
......@@ -306,13 +306,6 @@ class MediaImageTest extends EntityEmbedTestBase {
->set('settings.title_field', FALSE)
->save();
$field = FieldConfig::load('media.image.field_media_image');
$settings = $field->getSettings();
$settings['alt_field'] = FALSE;
$settings['title_field'] = FALSE;
$field->set('settings', $settings);
$field->save();
drupal_flush_all_caches();
$this->reopenDialog();
......@@ -378,28 +371,6 @@ class MediaImageTest extends EntityEmbedTestBase {
$settings = $field->getSettings();
$settings['alt_field'] = TRUE;
$settings['title_field'] = TRUE;
$settings['alt_field_required'] = FALSE;
$settings['title_field_required'] = TRUE;
$field->set('settings', $settings);
$field->save();
drupal_flush_all_caches();
$this->reopenDialog();
$alt = $this->assertSession()
->fieldExists('attributes[data-entity-embed-display-settings][alt]');
$this->assertFalse($alt->hasAttribute('required'));
$title = $this->assertSession()
->fieldExists('attributes[data-entity-embed-display-settings][title]');
$this->assertTrue($title->hasAttribute('required'));
$this->submitDialog();
$field = FieldConfig::load('media.image.field_media_image');
$settings = $field->getSettings();
$settings['alt_field_required'] = TRUE;
$settings['title_field_required'] = FALSE;
$field->set('settings', $settings);
$field->save();
......@@ -407,13 +378,6 @@ class MediaImageTest extends EntityEmbedTestBase {
$this->reopenDialog();
$alt = $this->assertSession()
->fieldExists('attributes[data-entity-embed-display-settings][alt]');
$this->assertTrue($alt->hasAttribute('required'));
$title = $this->assertSession()
->fieldExists('attributes[data-entity-embed-display-settings][title]');
$this->assertFalse($title->hasAttribute('required'));
// Test that setting value to double quote will allow setting the alt
// and title to empty.
$alt->setValue(MediaImageDecorator::EMPTY_STRING);
......@@ -424,6 +388,16 @@ class MediaImageTest extends EntityEmbedTestBase {
$img = $this->assertSession()->elementExists('css', 'img');
$this->assertEmpty($img->getAttribute('alt'));
$this->assertEmpty($img->getAttribute('title'));
$this->reopenDialog();
// Test that *not* filling out the fields makes it fall back to the default.
$alt->setValue('');
$title->setValue('');
$this->submitDialog();
$img = $this->assertSession()->elementExists('css', 'img');
$this->assertEquals('default alt', $img->getAttribute('alt'));
$this->assertEquals('default title', $img->getAttribute('title'));
}
/**
......
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