You are here

public function StatesListFormatter::viewElements in Workflows Field 8

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

Class

StatesListFormatter
Plugin implementation of the 'workflows_field_state_list' formatter.

Namespace

Drupal\workflows_field\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  foreach ($items as $delta => $item) {
    $elements[$delta] = [
      '#theme' => 'item_list__states_list',
      '#context' => [
        'list_style' => 'workflows-states-list',
      ],
      '#attributes' => [
        'class' => [
          Html::cleanCssIdentifier($item->value) . '--active',
        ],
      ],
      '#items' => $this
        ->buildItems($item),
    ];
  }
  return $elements;
}