You are here

public function UrlPlainFormatter::viewElements in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter::viewElements()

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

core/modules/file/src/Plugin/Field/FieldFormatter/UrlPlainFormatter.php, line 28
Contains \Drupal\file\Plugin\Field\FieldFormatter\UrlPlainFormatter.

Class

UrlPlainFormatter
Plugin implementation of the 'file_url_plain' formatter.

Namespace

Drupal\file\Plugin\Field\FieldFormatter

Code

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