public function SVG::getMetadata in SVG Image Field 2.0.x
Same name and namespace in other branches
- 2.1.x src/Plugin/media/Source/SVG.php \Drupal\svg_image_field\Plugin\media\Source\SVG::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 File::getMetadata
File
- src/
Plugin/ media/ Source/ SVG.php, line 33
Class
- SVG
- Provides media type plugin for SVG image field.
Namespace
Drupal\svg_image_field\Plugin\media\SourceCode
public function getMetadata(MediaInterface $media, $name) {
/** @var \Drupal\file\FileInterface $file */
$file = $media
->get($this->configuration['source_field'])->entity;
// If the source field is not required, it may be empty.
if (!$file) {
return parent::getMetadata($media, $name);
}
// Use the SVG file as the thumbnail. This may cause no thumbnail to be
// output depending on your image processor and image style output for
// the thumbnail.
// See https://drupal.org/i/3105482 for more info.
if ($name === 'thumbnail_uri') {
return $file
->getFileUri();
}
if ($name === 'thumbnail_alt_value') {
return $media
->get($this->configuration['source_field'])->alt ?: parent::getMetadata($media, $name);
}
return parent::getMetadata($media, $name);
}