Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
Overrides FormatterInterface::viewElements
public function viewElements(EntityInterface $entity, $langcode, array $items) {
// 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 ($items as $item) {
if ($item['display']) {
$entity->rss_elements[] = array(
'key' => 'enclosure',
'attributes' => array(
'url' => file_create_url($item['uri']),
'length' => $item['filesize'],
'type' => $item['filemime'],
),
);
break;
}
}
}