function UrlPlainFormatter::viewElements

Same name in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter::viewElements()
  2. 8.9.x core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter::viewElements()
  3. 11.x core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter::viewElements()

Overrides FormatterInterface::viewElements

File

core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php, line 25

Class

UrlPlainFormatter
Plugin implementation of the 'file_url_plain' formatter.

Namespace

Drupal\file\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
        assert($file instanceof FileInterface);
        $elements[$delta] = [
            '#markup' => $file->createFileUrl(),
            '#cache' => [
                'tags' => $file->getCacheTags(),
            ],
        ];
    }
    return $elements;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.