Plugin implementation of the 'file_rss_enclosure' formatter.
@FieldFormatter(
id = "file_rss_enclosure",
module = "file",
label = @Translation("RSS enclosure"),
field_types = {
"file"
}
)
Expanded class hierarchy of RSSEnclosureFormatter
class RSSEnclosureFormatter extends FormatterBase {
/**
* Implements \Drupal\field\Plugin\Type\Formatter\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;
}
}
}
}