class RSSEnclosureFormatter
Same name in other branches
- 9 core/modules/file/src/Plugin/Field/FieldFormatter/RSSEnclosureFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\RSSEnclosureFormatter
- 8.9.x core/modules/file/src/Plugin/Field/FieldFormatter/RSSEnclosureFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\RSSEnclosureFormatter
- 10 core/modules/file/src/Plugin/Field/FieldFormatter/RSSEnclosureFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\RSSEnclosureFormatter
Plugin implementation of the 'file_rss_enclosure' formatter.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Field\PluginSettingsBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface
- class \Drupal\Core\Field\FormatterBase extends \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase extends \Drupal\Core\Field\FormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase extends \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\RSSEnclosureFormatter extends \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase extends \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase
- class \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase extends \Drupal\Core\Field\FormatterBase
- class \Drupal\Core\Field\FormatterBase extends \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Field\PluginSettingsBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of RSSEnclosureFormatter
File
-
core/
modules/ file/ src/ Plugin/ Field/ FieldFormatter/ RSSEnclosureFormatter.php, line 12
Namespace
Drupal\file\Plugin\Field\FieldFormatterView source
class RSSEnclosureFormatter extends FileFormatterBase {
/**
* {@inheritdoc}
*/
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://wikipedia.org/wiki/RSS_enclosure
foreach ($this->getEntitiesToView($items, $langcode) as $file) {
/** @var \Drupal\file\FileInterface $file */
$entity->rss_elements[] = [
'key' => 'enclosure',
'attributes' => [
// In RSS feeds, it is necessary to use absolute URLs. The 'url.site'
// cache context is already associated with RSS feed responses, so it
// does not need to be specified here.
'url' => $file->createFileUrl(FALSE),
'length' => $file->getSize(),
'type' => $file->getMimeType(),
],
];
}
return [];
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.