You are here

public function FileLinkSeparateFormatter::viewElements in File Link 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldFormatter/FileLinkSeparateFormatter.php \Drupal\file_link\Plugin\Field\FieldFormatter\FileLinkSeparateFormatter::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 LinkSeparateFormatter::viewElements

File

src/Plugin/Field/FieldFormatter/FileLinkSeparateFormatter.php, line 27

Class

FileLinkSeparateFormatter
Plugin implementation of the 'file_link_separate' formatter.

Namespace

Drupal\file_link\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $element = parent::viewElements($items, $langcode);
  foreach ($items as $delta => $item) {
    if (isset($element[$delta])) {
      $element[$delta]['#theme'] = 'file_link_formatter_link_separate';
      $element[$delta] += [
        '#size' => $this
          ->getSetting('format_size') ? format_size($item->size) : $item->size,
        '#format' => $item->format,
      ];
    }
  }
  return $element;
}