public function FontAwesomeIconMedia::getMetadata in Font Awesome Icons 8.2
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
File
- modules/
fontawesome_media/ src/ Plugin/ media/ Source/ FontAwesomeIconMedia.php, line 36
Class
- FontAwesomeIconMedia
- Media source wrapping around a Font Awesome icon field.
Namespace
Drupal\fontawesome_media\Plugin\media\SourceCode
public function getMetadata(MediaInterface $media, $attribute_name) {
/** @var \Drupal\fontawesome\Plugin\Field\FieldType\FontAwesomeIcon $icon */
$icon = $media
->get($this->configuration['source_field'])
->first();
// If the source field is not required, it may be empty.
if (!$icon) {
return parent::getMetadata($media, $attribute_name);
}
switch ($attribute_name) {
case 'default_name':
return $icon
->get('icon_name')
->getValue();
case 'thumbnail_uri':
return $this
->getThumbnail($icon);
default:
return parent::getMetadata($media, $attribute_name);
}
}