You are here

protected function FieldTimerCountdownFormatterBase::preparePluginSettings in Field Timer 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatterBase.php \Drupal\field_timer\Plugin\Field\FieldFormatter\FieldTimerCountdownFormatterBase::preparePluginSettings()

Prepares array of settings used to initialize jQuery plugin.

Parameters

\Drupal\Core\Field\FieldItemInterface $item: Field item.

string $langcode: Langcode value.

Return value

array Array of key-value pairs.

Overrides FieldTimerJsFormatterBase::preparePluginSettings

1 call to FieldTimerCountdownFormatterBase::preparePluginSettings()
FieldTimerCountdownFormatter::preparePluginSettings in src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php
Prepares array of settings used to initialize jQuery plugin.
1 method overrides FieldTimerCountdownFormatterBase::preparePluginSettings()
FieldTimerCountdownFormatter::preparePluginSettings in src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php
Prepares array of settings used to initialize jQuery plugin.

File

src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatterBase.php, line 102

Class

FieldTimerCountdownFormatterBase
Base implementation of formatters that uses jQuery Countdown plugin.

Namespace

Drupal\field_timer\Plugin\Field\FieldFormatter

Code

protected function preparePluginSettings(FieldItemInterface $item, $langcode) {
  $settings = $this
    ->getSettings();
  $timestamp = $this
    ->getTimestamp($item);
  $type = $this
    ->getSetting('type');
  if ($type == 'timer' || $type == 'auto' && $timestamp <= REQUEST_TIME) {
    $settings['until'] = FALSE;
    $settings['since'] = TRUE;
  }
  elseif ($type == 'countdown' || $type == 'auto' && $timestamp > REQUEST_TIME) {
    $settings['until'] = TRUE;
    $settings['since'] = FALSE;
  }
  unset($settings['type']);
  return $settings;
}