You are here

public function GeolocationItemTokenTrait::getTokenHelp in Geolocation Field 8

Return token form element.

2 calls to GeolocationItemTokenTrait::getTokenHelp()
GeolocationGoogleMapFormatter::settingsForm in src/Plugin/Field/FieldFormatter/GeolocationGoogleMapFormatter.php
Returns a form to configure settings for the formatter.
GeolocationTokenFormatter::settingsForm in src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php
Returns a form to configure settings for the formatter.

File

src/GeolocationItemTokenTrait.php, line 15

Class

GeolocationItemTokenTrait
Class GeolocationItemTokenTrait - Provide Token for geolocation items.

Namespace

Drupal\geolocation

Code

public function getTokenHelp() {
  $element = [];

  // Add the token UI from the token module if present.
  $element['token_items'] = [
    '#type' => 'table',
    '#caption' => $this
      ->t('Geolocation Item Tokens'),
    '#header' => [
      $this
        ->t('Token'),
      $this
        ->t('Description'),
    ],
  ];

  // Value tokens.
  $element['token_items'][] = [
    'token' => [
      '#plain_text' => '[geolocation_current_item:lat]',
    ],
    'description' => [
      '#plain_text' => $this
        ->t('Current value latitude'),
    ],
  ];
  $element['token_items'][] = [
    'token' => [
      '#plain_text' => '[geolocation_current_item:lng]',
    ],
    'description' => [
      '#plain_text' => $this
        ->t('Current value longitude'),
    ],
  ];

  // Sexagesimal tokens.
  $element['token_items'][] = [
    'token' => [
      '#plain_text' => '[geolocation_current_item:lng_sex]',
    ],
    'description' => [
      '#plain_text' => $this
        ->t('Current value longitude in sexagesimal notation.'),
    ],
  ];
  $element['token_items'][] = [
    'token' => [
      '#plain_text' => '[geolocation_current_item:lng_sex]',
    ],
    'description' => [
      '#plain_text' => $this
        ->t('Current value longitude in sexagesimal notation'),
    ],
  ];

  // Raw tokens.
  $element['token_items'][] = [
    'token' => [
      '#plain_text' => '[geolocation_current_item:lat_sin]',
    ],
    'description' => [
      '#plain_text' => $this
        ->t('Add description'),
    ],
  ];
  $element['token_items'][] = [
    'token' => [
      '#plain_text' => '[geolocation_current_item:lat_cos]',
    ],
    'description' => [
      '#plain_text' => $this
        ->t('Add description'),
    ],
  ];
  $element['token_items'][] = [
    'token' => [
      '#plain_text' => '[geolocation_current_item:lng_rad]',
    ],
    'description' => [
      '#plain_text' => $this
        ->t('Add description'),
    ],
  ];
  $element['token_items'][] = [
    'token' => [
      '#plain_text' => '[geolocation_current_item:data:?]',
    ],
    'description' => [
      '#plain_text' => $this
        ->t('Data stored with the field item'),
    ],
  ];
  if (\Drupal::service('module_handler')
    ->moduleExists('token') && method_exists($this->fieldDefinition, 'getTargetEntityTypeId')) {

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