UrlPlainFormatter.php

Same filename in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php
  2. 8.9.x core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php
  3. 10 core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php

Namespace

Drupal\file\Plugin\Field\FieldFormatter

File

core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php

View source
<?php

namespace Drupal\file\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\Attribute\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\file\FileInterface;

/**
 * Plugin implementation of the 'file_url_plain' formatter.
 */
class UrlPlainFormatter extends FileFormatterBase {
    
    /**
     * {@inheritdoc}
     */
    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;
    }

}

Classes

Title Deprecated Summary
UrlPlainFormatter Plugin implementation of the 'file_url_plain' formatter.

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