You are here

public function Count::viewElements in Field Count Formatter 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldFormatter/Count.php \Drupal\field_count_formatter\Plugin\Field\FieldFormatter\Count::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

src/Plugin/Field/FieldFormatter/Count.php, line 37
Contains \Drupal\field_count_formatter\Plugin\Field\FieldFormatter\Count.

Class

Count
Plugin implementation of the 'CountFormatter' formatter.

Namespace

Drupal\field_count_formatter\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {

  // Needs to be nested (element 0) so we preserve the default field title rendering.
  return array(
    array(
      '#type' => 'markup',
      '#markup' => $items
        ->count(),
    ),
  );
}