You are here

public function DataProviderBase::getTokenHelp in Geolocation Field 8.2

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

Return field item tokens.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $fieldDefinitionInterface: Field definition interface.

Return value

array Token help element.

Overrides DataProviderInterface::getTokenHelp

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

File

src/DataProviderBase.php, line 77

Class

DataProviderBase
Class DataProviderBase.

Namespace

Drupal\geolocation

Code

public function getTokenHelp(FieldDefinitionInterface $fieldDefinition = NULL) {
  if (empty($fieldDefinition)) {
    $fieldDefinition = $this->fieldDefinition;
  }
  $element = [];
  $element['token_items'] = [
    '#type' => 'table',
    '#prefix' => '<h4>' . $this
      ->t('Geolocation Item Tokens') . '</h4>',
    '#header' => [
      $this
        ->t('Token'),
      $this
        ->t('Description'),
    ],
  ];
  foreach ($fieldDefinition
    ->getFieldStorageDefinition()
    ->getColumns() as $id => $column) {
    $item = [
      'token' => [
        '#plain_text' => '[geolocation_current_item:' . $id . ']',
      ],
    ];
    if (!empty($column['description'])) {
      $item['description'] = [
        '#plain_text' => $column['description'],
      ];
    }
    $element['token_items'][] = $item;
  }
  if (\Drupal::service('module_handler')
    ->moduleExists('token') && method_exists($fieldDefinition, 'getTargetEntityTypeId')) {

    // Add the token UI from the token module if present.
    $element['token_help'] = [
      '#theme' => 'token_tree_link',
      '#prefix' => '<h4>' . $this
        ->t('Additional Tokens') . '</h4>',
      '#token_types' => [
        $fieldDefinition
          ->getTargetEntityTypeId(),
      ],
      '#weight' => 100,
    ];
  }
  return $element;
}