protected function Book::prepareAttachment in Open Social 10.0.x
Same name and namespace in other branches
- 10.3.x modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::prepareAttachment()
- 10.1.x modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::prepareAttachment()
- 10.2.x modules/custom/social_demo/src/Plugin/DemoContent/Book.php \Drupal\social_demo\Plugin\DemoContent\Book::prepareAttachment()
Returns reference to attachment, possibly with a description.
Parameters
array $files: Array with UUIDs of files.
Return value
array|null Array containing related files or NULL.
1 call to Book::prepareAttachment()
- Book::getEntry in modules/
custom/ social_demo/ src/ Plugin/ DemoContent/ Book.php - Makes an array with data of an entity.
File
- modules/
custom/ social_demo/ src/ Plugin/ DemoContent/ Book.php, line 119
Class
- Book
- Book Plugin for demo content.
Namespace
Drupal\social_demo\Plugin\DemoContentCode
protected function prepareAttachment(array $files) {
$attachments = NULL;
foreach ($files as $file) {
$description = '';
// If it is an array, this means we also have a description.
$uuid = $file;
if (is_array($file)) {
$uuid = key($file);
$description = current($file);
}
$object = $this->fileStorage
->loadByProperties([
'uuid' => $uuid,
]);
if ($object) {
$properties = [
'target_id' => current($object)
->id(),
'description' => $description,
];
$attachments[] = $properties;
}
}
return $attachments;
}