Issue #3319601 by pooja_sharma, sunlix, bkosborne, quietone, smustgrave, longwave, lendude: Media image thumbnail incorrectly ends up as NULL when it should be an empty string
(cherry picked from commit 22ee9bdbe3
)
merge-requests/9907/head
parent
4ba08a0254
commit
5f4c47f32f
|
@ -144,7 +144,7 @@ class Image extends File {
|
|||
return $uri;
|
||||
|
||||
case 'thumbnail_alt_value':
|
||||
return $media->get($this->configuration['source_field'])->alt ?: parent::getMetadata($media, $name);
|
||||
return $media->get($this->configuration['source_field'])->alt ?? parent::getMetadata($media, $name);
|
||||
}
|
||||
|
||||
return parent::getMetadata($media, $name);
|
||||
|
|
|
@ -8,6 +8,9 @@ use Drupal\language\Entity\ConfigurableLanguage;
|
|||
use Drupal\media\Entity\Media;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* Tests the Media overview page.
|
||||
|
@ -16,6 +19,8 @@ use Drupal\user\RoleInterface;
|
|||
*/
|
||||
class MediaOverviewPageTest extends MediaFunctionalTestBase {
|
||||
|
||||
use TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -185,4 +190,50 @@ class MediaOverviewPageTest extends MediaFunctionalTestBase {
|
|||
$assert_session->linkByHrefExists('/media/' . $media3->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the display of the alt attribute.
|
||||
*/
|
||||
public function testImageAltTextDisplay(): void {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$media_type = $this->createMediaType('image');
|
||||
$media_type_id = $media_type->id();
|
||||
$media_type->setFieldMap(['name' => 'name']);
|
||||
$media_type->save();
|
||||
|
||||
/** @var \Drupal\field\FieldConfigInterface $field */
|
||||
$field = FieldConfig::load("media.$media_type_id.field_media_image");
|
||||
$settings = $field->getSettings();
|
||||
$settings['alt_field'] = TRUE;
|
||||
$settings['alt_field_required'] = FALSE;
|
||||
$field->set('settings', $settings);
|
||||
$field->save();
|
||||
|
||||
$file = File::create([
|
||||
'uri' => $this->getTestFiles('image')[0]->uri,
|
||||
]);
|
||||
$file->save();
|
||||
|
||||
// Set the alt text to an empty string.
|
||||
$media = Media::create([
|
||||
'name' => 'Custom name',
|
||||
'bundle' => $media_type_id,
|
||||
'field_media_image' => [
|
||||
[
|
||||
'target_id' => $file->id(),
|
||||
'alt' => '',
|
||||
'title' => 'default title',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$media->save();
|
||||
|
||||
$this->drupalGet('/admin/content/media');
|
||||
|
||||
// Confirm that the alt text attribute is present.
|
||||
$assert_session = $this->assertSession();
|
||||
$element = $assert_session->elementAttributeExists('css', 'td.views-field-thumbnail__target-id img', 'alt');
|
||||
$this->assertSame('', (string) $element->getAttribute('alt'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue