diff --git a/fivestar.module b/fivestar.module index 021e0d3..ecc342e 100644 --- a/fivestar.module +++ b/fivestar.module @@ -253,3 +253,27 @@ function fivestar_library_info_build() { } return $libraries; } + +/** + * Implements hook_token_info_alter(). + * + * This adds the missing token info for automatically detected tokens. + */ + +function fivestar_token_info_alter(&$info) { + $entities = \Drupal::service('entity_field.manager')->getFieldMap(); + foreach ($entities as $entity_key => $entity) { + + foreach ($entity as $field_key => $field) { + if ($field['type'] !== 'fivestar' ) { + continue; + } + + $token_key = sprintf('%s-%s', $entity_key, $field_key); + $info['tokens'][$token_key]['target'] = [ + 'name' => t('Target'), + 'description' => t('Fivestar target.'), + ]; + } + } +}