private function AudioFieldPluginBase::getUniqueId in AudioField 8
Get a unique ID for an item.
Parameters
\Drupal\file\Plugin\Field\FieldType\FileItem|\Drupal\link\Plugin\Field\FieldType\LinkItem $item: Item for which we are generating a unique ID.
Return value
string Unique ID for the item.
1 call to AudioFieldPluginBase::getUniqueId()
- AudioFieldPluginBase::getAudioRenderInfo in src/
AudioFieldPluginBase.php - Get required rendering information from an entity.
File
- src/
AudioFieldPluginBase.php, line 406
Class
- AudioFieldPluginBase
- Base class for audiofield plugins. Includes global functions.
Namespace
Drupal\audiofieldCode
private function getUniqueId($item) {
// Used to generate unique container.
$random_generator = new Random();
// Handle File entity.
if ($this
->getClassType($item) == 'FileItem') {
// Load the associated file.
$file = $this
->loadFileFromItem($item);
// Craft a unique ID.
return Html::getUniqueId('file_' . $file
->get('fid')
->getValue()[0]['value'] . '_' . $random_generator
->name(16, TRUE));
}
elseif ($this
->getClassType($item) == 'LinkItem') {
// Craft a unique ID.
return Html::getUniqueId('item_' . $random_generator
->name(16, TRUE));
}
return Html::getUniqueId($random_generator
->name(16, TRUE));
}