3 namespace Drupal\file\Plugin\Field\FieldFormatter;
5 use Drupal\Core\Field\FieldItemListInterface;
8 * Plugin implementation of the 'file_default' formatter.
11 * id = "file_default",
12 * label = @Translation("Generic file"),
18 class GenericFileFormatter extends FileFormatterBase {
23 public function viewElements(FieldItemListInterface $items, $langcode) {
26 foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
27 $item = $file->_referringItem;
29 '#theme' => 'file_link',
31 '#description' => $item->description,
33 'tags' => $file->getCacheTags(),
36 // Pass field item attributes to the theme function.
37 if (isset($item->_attributes)) {
38 $elements[$delta] += ['#attributes' => []];
39 $elements[$delta]['#attributes'] += $item->_attributes;
40 // Unset field item attributes since they have been included in the
41 // formatter output and should not be rendered in the field template.
42 unset($item->_attributes);