private function AudioFieldPluginBase::getAudioDescription in AudioField 8
Get a title description from an audiofield entity.
Parameters
\Drupal\file\Plugin\Field\FieldType\FileItem|\Drupal\link\Plugin\Field\FieldType\LinkItem $item: Item for which a title is being generated.
Return value
string The description of an entity.
2 calls to AudioFieldPluginBase::getAudioDescription()
- AudioFieldPluginBase::createDownloadList in src/
AudioFieldPluginBase.php - Used to render list of downloads as an item list.
- AudioFieldPluginBase::getAudioRenderInfo in src/
AudioFieldPluginBase.php - Get required rendering information from an entity.
File
- src/
AudioFieldPluginBase.php, line 483
Class
- AudioFieldPluginBase
- Base class for audiofield plugins. Includes global functions.
Namespace
Drupal\audiofieldCode
private function getAudioDescription($item) {
if ($this
->getClassType($item) == 'FileItem') {
// Get the file description - use the filename if it doesn't exist.
$entity_description = $item
->get('description')
->getString();
if (empty($entity_description)) {
// Load the associated file.
$file = $this
->loadFileFromItem($item);
return $file
->getFilename();
}
return $entity_description;
}
elseif ($this
->getClassType($item) == 'LinkItem') {
// Get the file description - use the filename if it doesn't exist.
$entity_description = $item
->get('title')
->getString();
if (empty($entity_description)) {
return $item
->getUrl()
->toString();
}
return $entity_description;
}
return '';
}