You are here

protected function FieldTimerJsFormatterBase::generateJsSettings 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::generateJsSettings()

Generates JS settings for the field.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: Field items.

string $langcode: Langcode value.

Return value

array Array of JS settings to be used to initialize timer/countdown widget.

1 call to FieldTimerJsFormatterBase::generateJsSettings()
FieldTimerJsFormatterBase::viewElements in src/Plugin/Field/FieldFormatter/FieldTimerJsFormatterBase.php
Builds a renderable array for a field value.

File

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

Class

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

Namespace

Drupal\field_timer\Plugin\Field\FieldFormatter

Code

protected function generateJsSettings(FieldItemListInterface $items, $langcode) {
  $keys = $this
    ->getItemKeys($items);
  $js_settings = [];
  foreach ($items as $delta => $item) {
    $timestamp = $this
      ->getTimestamp($item);
    if ($timestamp !== NULL) {
      $js_settings[$keys[$delta]]['settings'] = $this
        ->preparePluginSettings($item, $langcode);
      $js_settings[$keys[$delta]]['plugin'] = static::JS_KEY;
    }
  }
  return $js_settings;
}