You are here

public function DataProviderBase::replaceFieldItemTokens in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 src/DataProviderBase.php \Drupal\geolocation\DataProviderBase::replaceFieldItemTokens()

Replace field item tokens.

Parameters

string $text: Text.

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

Return value

array Retrieved locations.

Overrides DataProviderInterface::replaceFieldItemTokens

1 call to DataProviderBase::replaceFieldItemTokens()
GeolocationFieldProvider::replaceFieldItemTokens in src/Plugin/geolocation/DataProvider/GeolocationFieldProvider.php
Replace field item tokens.
1 method overrides DataProviderBase::replaceFieldItemTokens()
GeolocationFieldProvider::replaceFieldItemTokens in src/Plugin/geolocation/DataProvider/GeolocationFieldProvider.php
Replace field item tokens.

File

src/DataProviderBase.php, line 124

Class

DataProviderBase
Class DataProviderBase.

Namespace

Drupal\geolocation

Code

public function replaceFieldItemTokens($text, FieldItemInterface $fieldItem) {
  $token_context['geolocation_current_item'] = $fieldItem;
  $entity = NULL;
  try {
    $entity = $fieldItem
      ->getParent()
      ->getParent()
      ->getValue();
  } catch (\Exception $e) {
  }
  if (is_object($entity) && $entity instanceof ContentEntityInterface) {
    $token_context[$entity
      ->getEntityTypeId()] = $entity;
  }
  $text = \Drupal::token()
    ->replace($text, $token_context, [
    'callback' => [
      $this,
      'fieldItemTokens',
    ],
    'clear' => TRUE,
  ]);
  $text = Html::decodeEntities($text);
  return $text;
}