You are here

function country_token_info in Country 8

Implements hook_token_info().

File

./country.tokens.inc, line 14
Provides Token integration for country.

Code

function country_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;
    }

    // Build country name tokens for all country fields.
    $fields = \Drupal::service('entity_field.manager')
      ->getFieldStorageDefinitions($entity_type_id);
    foreach ($fields as $field_name => $field) {
      if ($field
        ->getType() != 'country') {
        continue;
      }
      $tokens[$token_type . '-' . $field_name]['country_original_name'] = [
        'name' => t('The country name'),
        'description' => NULL,
        'module' => 'country',
      ];
    }
  }
  return [
    'types' => $types,
    'tokens' => $tokens,
  ];
}