class UrlPlainFormatter

Same name and namespace in other branches
  1. 10 core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter
  2. 11.x core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter
  3. 8.9.x core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter

Plugin implementation of the 'file_url_plain' formatter.

Plugin annotation


@FieldFormatter(
  id = "file_url_plain",
  label = @Translation("URL to file"),
  field_types = {
    "file"
  }
)

Hierarchy

Expanded class hierarchy of UrlPlainFormatter

File

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

Namespace

Drupal\file\Plugin\Field\FieldFormatter
View source
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;
  }

}

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