public function Test::getMetadataAttributes in Drupal 10
Same name and namespace in other branches
- 8 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php \Drupal\media_test_source\Plugin\media\Source\Test::getMetadataAttributes()
- 9 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/Test.php \Drupal\media_test_source\Plugin\media\Source\Test::getMetadataAttributes()
Gets a list of metadata attributes provided by this plugin.
Most media sources have associated metadata, describing attributes such as:
- dimensions
- duration
- encoding
- date
- location
- permalink
- licensing information
- ...
This method should list all metadata attributes that a media source MAY offer. In other words: it is possible that a particular media item does not contain a certain attribute. For example: an oEmbed media source can contain both video and images. Images don't have a duration, but videos do.
(The term 'attributes' was chosen because it cannot be confused with 'fields' and 'properties', both of which are concepts in Drupal's Entity Field API.)
Return value
array Associative array with:
- keys: metadata attribute names
- values: human-readable labels for those attribute names
Overrides MediaSourceInterface::getMetadataAttributes
File
- core/
modules/ media/ tests/ modules/ media_test_source/ src/ Plugin/ media/ Source/ Test.php, line 25
Class
- Test
- Provides test media source.
Namespace
Drupal\media_test_source\Plugin\media\SourceCode
public function getMetadataAttributes() {
// The metadata attributes are kept in state storage. This allows tests to
// change the metadata attributes and makes it easier to test different
// variations.
$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',
],
]);
return array_map(function ($item) {
return $item['label'];
}, $attributes);
}