public function RSSEnclosureFormatter::viewElements in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Plugin/Field/FieldFormatter/RSSEnclosureFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\RSSEnclosureFormatter::viewElements()
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
- core/
modules/ file/ src/ Plugin/ Field/ FieldFormatter/ RSSEnclosureFormatter.php, line 28 - Contains \Drupal\file\Plugin\Field\FieldFormatter\RSSEnclosureFormatter.
Class
- RSSEnclosureFormatter
- Plugin implementation of the 'file_rss_enclosure' formatter.
Namespace
Drupal\file\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$entity = $items
->getEntity();
// Add the first file as an enclosure to the RSS item. RSS allows only one
// enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
foreach ($this
->getEntitiesToView($items, $langcode) as $delta => $file) {
$entity->rss_elements[] = array(
'key' => 'enclosure',
'attributes' => array(
'url' => file_create_url($file
->getFileUri()),
'length' => $file
->getSize(),
'type' => $file
->getMimeType(),
),
);
}
return [];
}