You are here

public function Test::getMetadata in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php \Drupal\media_test_source\Plugin\media\Source\Test::getMetadata()
  2. 10 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php \Drupal\media_test_source\Plugin\media\Source\Test::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 MediaSourceBase::getMetadata

1 call to Test::getMetadata()
TestTranslation::getMetadata in core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php
Gets the value for a metadata attribute for a given media item.
1 method overrides Test::getMetadata()
TestTranslation::getMetadata in core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestTranslation.php
Gets the value for a metadata attribute for a given media item.

File

core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php, line 41

Class

Test
Provides test media source.

Namespace

Drupal\media_test_source\Plugin\media\Source

Code

public function getMetadata(MediaInterface $media, $attribute_name) {
  $attributes = \Drupal::state()
    ->get('media_source_test_attributes', [
    'attribute_1' => [
      'label' => $this
        ->t('Attribute 1'),
      'value' => 'Value 1',
    ],
    'attribute_2' => [
      'label' => $this
        ->t('Attribute 2'),
      'value' => 'Value 1',
    ],
  ]);
  if (in_array($attribute_name, array_keys($attributes))) {
    return $attributes[$attribute_name]['value'];
  }
  return parent::getMetadata($media, $attribute_name);
}