You are here

function geolocation_token_info in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 geolocation.tokens.inc \geolocation_token_info()

Implements hook_token_info().

File

./geolocation.tokens.inc, line 14
Token integration geolocation field type.

Code

function geolocation_token_info() {
  $types = [];
  $tokens = [];
  foreach (\Drupal::entityTypeManager()
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if (!$entity_type
      ->entityClassImplements(ContentEntityInterface::class)) {
      continue;
    }
    $token_type = \Drupal::service('token.entity_mapper')
      ->getTokenTypeForEntityType($entity_type_id);
    if (empty($token_type)) {
      continue;
    }

    /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $fields */
    $fields = \Drupal::service('entity_field.manager')
      ->getFieldStorageDefinitions($entity_type_id);
    foreach ($fields as $field_name => $field) {
      if ($field
        ->getType() != 'geolocation') {
        continue;
      }
      $tokens[$token_type . '-' . $field_name]['lat_sex'] = [
        'name' => t("Latitude in sexagesimal notation"),
        'description' => NULL,
        'module' => 'geolocation',
      ];
      $tokens[$token_type . '-' . $field_name]['lng_sex'] = [
        'name' => t("Longitude in sexagesimal notation"),
        'description' => NULL,
        'module' => 'geolocation',
      ];
      $tokens[$token_type . '-' . $field_name]['data'] = [
        'name' => t("Data"),
        'description' => NULL,
        'module' => 'geolocation',
      ];
    }
  }
  return [
    'types' => $types,
    'tokens' => $tokens,
  ];
}