diff --git a/token.module b/token.module index ff0c3dbf45b0d5753943e5ee376eff53aefff1e1..fcc72ba9cb3e268838cfd4b3eeacb5834f403970 100644 --- a/token.module +++ b/token.module @@ -205,29 +205,6 @@ function token_entity_type_alter(array &$entity_types) { } } -/** - * Implements hook_module_implements_alter(). - * - * Adds missing token support for core modules. - */ -function token_module_implements_alter(&$implementations, $hook) { - \Drupal::moduleHandler()->loadInclude('token', 'inc', 'token.tokens'); - - if ($hook == 'tokens' || $hook == 'token_info' || $hook == 'token_info_alter' || $hook == 'tokens_alter') { - foreach (_token_core_supported_modules() as $module) { - if (\Drupal::moduleHandler()->moduleExists($module) && function_exists($module . '_' . $hook)) { - $implementations[$module] = TRUE; - } - } - // Move token.module to get included first since it is responsible for - // other modules. - if (isset($implementations['token'])) { - unset($implementations['token']); - $implementations = array_merge(['token' => 'tokens'], $implementations); - } - } -} - /** * Return the module responsible for a token. * diff --git a/token.tokens.inc b/token.tokens.inc index eeab9054182396782e33a535523b0ce5bfa2b536..2cf921515f1192436fa06a681efa65af7d5490ec 100755 --- a/token.tokens.inc +++ b/token.tokens.inc @@ -123,12 +123,27 @@ function token_token_info_alter(&$info) { ]; } } + + // Call proxy implementations. + if (\Drupal::moduleHandler()->moduleExists('field')) { + _field_token_info_alter($info); + } } /** * Implements hook_token_info(). */ function token_token_info() { + $info = []; + + // Call proxy implementations. + if (\Drupal::moduleHandler()->moduleExists('book')) { + $info += _book_token_info(); + } + if (\Drupal::moduleHandler()->moduleExists('menu_ui')) { + $info += _menu_ui_token_info(); + } + // Node tokens. if (\Drupal::moduleHandler()->moduleExists('node')) { $info['tokens']['node']['source'] = [ @@ -476,6 +491,18 @@ function token_token_info() { */ function token_tokens($type, array $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { $replacements = []; + + // Call proxy implementations. + if (\Drupal::moduleHandler()->moduleExists('book')) { + $replacements += _book_tokens($type, $tokens, $data, $options, $bubbleable_metadata); + } + if (\Drupal::moduleHandler()->moduleExists('menu_ui')) { + $replacements += _menu_ui_tokens($type, $tokens, $data, $options, $bubbleable_metadata); + } + if (\Drupal::moduleHandler()->moduleExists('field')) { + $replacements += _field_tokens($type, $tokens, $data, $options, $bubbleable_metadata); + } + $language_manager = \Drupal::languageManager(); $url_options = ['absolute' => TRUE]; if (isset($options['langcode'])) { @@ -1182,9 +1209,9 @@ function token_tokens($type, array $tokens, array $data, array $options, Bubblea } /** - * Implements hook_token_info() on behalf of book.module. + * Proxy implementation of hook_token_info() on behalf of book.module. */ -function book_token_info() { +function _book_token_info() { $info['types']['book'] = [ 'name' => t('Book'), 'description' => t('Tokens related to books.'), @@ -1225,9 +1252,9 @@ function book_token_info() { } /** - * Implements hook_tokens() on behalf of book.module. + * Proxy implementation of hook_tokens() on behalf of book.module. */ -function book_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { +function _book_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { $replacements = []; // Node tokens. @@ -1291,9 +1318,9 @@ function book_tokens($type, $tokens, array $data, array $options, BubbleableMeta } /** - * Implements hook_token_info() on behalf of menu_ui.module. + * Proxy implementation of hook_token_info() on behalf of menu_ui.module. */ -function menu_ui_token_info() { +function _menu_ui_token_info() { // Menu tokens. $info['types']['menu'] = [ 'name' => t('Menus'), @@ -1343,9 +1370,9 @@ function menu_ui_token_info() { } /** - * Implements hook_tokens() on behalf of menu_ui.module. + * Proxy implementation of hook_tokens() on behalf of menu_ui.module. */ -function menu_ui_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { +function _menu_ui_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { $replacements = []; /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */ @@ -1502,12 +1529,12 @@ function _token_menu_link_best_match(NodeInterface $node, array $links) { } /** - * Implements hook_token_info_alter() on behalf of field.module. + * Proxy implementation of hook_token_info_alter() on behalf of field.module. * * We use hook_token_info_alter() rather than hook_token_info() as other * modules may already have defined some field tokens. */ -function field_token_info_alter(&$info) { +function _field_token_info_alter(&$info) { $type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinitions(); // Attach field tokens to their respecitve entity tokens. @@ -1683,9 +1710,9 @@ function _token_field_label($entity_type, $field_name) { } /** - * Implements hook_tokens() on behalf of field.module. + * Proxy implementation of hook_tokens() on behalf of field.module. */ -function field_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { +function _field_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { $replacements = []; $langcode = isset($options['langcode']) ? $options['langcode'] : NULL;