You are here

public function FieldTimerJsFormatterBase::viewElements in Field Timer 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/FieldTimerJsFormatterBase.php \Drupal\field_timer\Plugin\Field\FieldFormatter\FieldTimerJsFormatterBase::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

3 calls to FieldTimerJsFormatterBase::viewElements()
FieldTimerCountdownFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php
Builds a renderable array for a field value.
FieldTimerCountdownLedFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldTImerCountdownLedFormatter.php
Builds a renderable array for a field value.
FieldTimerCountyFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldTimerCountyFormatter.php
Builds a renderable array for a field value.
3 methods override FieldTimerJsFormatterBase::viewElements()
FieldTimerCountdownFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php
Builds a renderable array for a field value.
FieldTimerCountdownLedFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldTImerCountdownLedFormatter.php
Builds a renderable array for a field value.
FieldTimerCountyFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldTimerCountyFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/FieldTimerJsFormatterBase.php, line 35

Class

FieldTimerJsFormatterBase
Implementation of formatters that uses JavaScript to render timer/countdown.

Namespace

Drupal\field_timer\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  $elements['#attached']['library'][] = 'field_timer/' . static::LIBRARY_NAME;
  $elements['#attached']['library'][] = 'field_timer/init';
  $elements['#attached']['drupalSettings']['field_timer'] = $this
    ->generateJsSettings($items, $langcode);
  return $elements;
}