You are here

public function TestTranslation::getMetadata in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php \Drupal\media_test_source\Plugin\media\Source\TestTranslation::getMetadata()
  2. 9 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php \Drupal\media_test_source\Plugin\media\Source\TestTranslation::getMetadata()

Gets the value for a metadata attribute for a given media item.

Parameters

\Drupal\media\MediaInterface $media: A media item.

string $attribute_name: Name of the attribute to fetch.

Return value

mixed|null Metadata attribute value or NULL if unavailable.

Overrides Test::getMetadata

File

core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php, line 23

Class

TestTranslation
Provides test media source.

Namespace

Drupal\media_test_source\Plugin\media\Source

Code

public function getMetadata(MediaInterface $media, $attribute_name) {
  if ($attribute_name == 'thumbnail_uri') {
    return 'public://' . $media
      ->language()
      ->getId() . '.png';
  }
  if ($attribute_name == 'test_thumbnail_alt') {
    $langcode = $media
      ->language()
      ->getId();
    return $this
      ->t('Test Thumbnail @language', [
      '@language' => $langcode,
    ], [
      'langcode' => $langcode,
    ]);
  }
  return parent::getMetadata($media, $attribute_name);
}