function Test::getMetadata

Same name 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. 8.9.x core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php \Drupal\media_test_source\Plugin\media\Source\Test::getMetadata()
  3. 10 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php \Drupal\media_test_source\Plugin\media\Source\Test::getMetadata()

Overrides MediaSourceBase::getMetadata

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 44

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.