public function Document::getField in Media entity document 8
Gets a media-related field/value.
Parameters
MediaInterface $media: Media object.
string $name: Name of field to fetch.
Return value
mixed Field value or FALSE if data unavailable.
Overrides MediaTypeInterface::getField
File
- src/
Plugin/ MediaEntity/ Type/ Document.php, line 36
Class
- Document
- Provides media type plugin for Document.
Namespace
Drupal\media_entity_document\Plugin\MediaEntity\TypeCode
public function getField(MediaInterface $media, $name) {
$source_field = $this->configuration['source_field'];
// Get the file document.
/** @var \Drupal\file\FileInterface $file */
$file = $media->{$source_field}->entity;
// Return the field.
switch ($name) {
case 'mime':
return !$file->filemime
->isEmpty() ? $file
->getMimeType() : FALSE;
case 'size':
$size = $file
->getSize();
return $size ? $size : FALSE;
}
return FALSE;
}