Skip to content
Snippets Groups Projects
Commit cc9bd24b authored by catch's avatar catch
Browse files

Issue #3319601 by pooja_sharma, sunlix, bkosborne, quietone, smustgrave,...

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 22ee9bdb)
parent 6dcad527
No related branches found
No related tags found
7 merge requests!10663Issue #3495778: Update phpdoc in FileSaveHtaccessLoggingTest,!10451Issue #3472458 by watergate, smustgrave: CKEditor 5 show blocks label is not translated,!10150Issue #3467294 by quietone, nod_, smustgrave, catch, longwave: Change string...,!10130Resolve #3480321 "Second level menu",!9936Issue #3483087: Check the module:// prefix in the translation server path and replace it with the actual module path,!9933Issue #3394728 by ankondrat4: Undefined array key "#prefix" and deprecated function: explode() in Drupal\file\Element\ManagedFile::uploadAjaxCallback(),!9914Issue #3451136 by quietone, gapple, ghost of drupal past: Improve...
Pipeline #316054 canceled
Pipeline: drupal

#316055

    ......@@ -144,7 +144,7 @@ public function getMetadata(MediaInterface $media, $name) {
    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\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 @@
    */
    class MediaOverviewPageTest extends MediaFunctionalTestBase {
    use TestFileCreationTrait;
    /**
    * {@inheritdoc}
    */
    ......@@ -185,4 +190,50 @@ public function testMediaOverviewPage(): void {
    $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'));
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment