You are here

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

Generates unique ids for the field items.

Parameters

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

Return value

array Array of ids keyed by field item delta.

4 calls to FieldTimerJsFormatterBase::getItemKeys()
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.
FieldTimerJsFormatterBase::generateJsSettings in src/Plugin/Field/FieldFormatter/FieldTimerJsFormatterBase.php
Generates JS settings for the field.

File

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

Class

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

Namespace

Drupal\field_timer\Plugin\Field\FieldFormatter

Code

protected function getItemKeys(FieldItemListInterface $items) {
  $entity = $items
    ->getEntity();
  if (!isset($this->itemKeys[$entity
    ->getEntityTypeId()][$entity
    ->id()][$items
    ->getFieldDefinition()
    ->getName()])) {
    $entity = $items
      ->getEntity();
    $this->itemKeys = [];
    foreach ($items as $delta => $item) {
      $this->itemKeys[$entity
        ->getEntityTypeId()][$entity
        ->id()][$items
        ->getFieldDefinition()
        ->getName()][$delta] = implode('-', [
        $entity
          ->getEntityTypeId(),
        $entity
          ->id(),
        $items
          ->getFieldDefinition()
          ->getName(),
        $delta,
        Crypt::randomBytesBase64(8),
      ]);
    }
  }
  return $this->itemKeys[$entity
    ->getEntityTypeId()][$entity
    ->id()][$items
    ->getFieldDefinition()
    ->getName()] ?? [];
}