public function EpubTableOfContent::viewElements in Epub 8
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides FormatterInterface::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ EpubTableOfContent.php, line 29 - Contains \Drupal\epub\Plugin\Field\FieldFormatter\EpubTableOfContent.
Class
- EpubTableOfContent
- Plugin implementation of the 'epub' formatter.
Namespace
Drupal\epub\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($this
->getEntitiesToView($items, $langcode) as $delta => $file) {
if ($file
->getMimeType() == 'application/epub+zip') {
$file_url = file_create_url($file
->getFileUri());
$dir = 'public://epub_content/' . $file
->id();
$elements[$delta] = array(
'#theme' => 'epub_formatter_toc',
'#file' => $file_url,
'#toc' => epub_get_toc($dir, '_blank'),
);
}
else {
$elements[$delta] = array(
'#theme' => 'file_link',
'#file' => $file,
);
}
}
return $elements;
}