سؤال

After enabling Token and Redirect modules, I've found at /admin/help/token that I can use Redirect tokens. For example:

Redirect tokens in Drupal at /admin/help/token

However, I've got the problem finding the place where and how these tokens are defined (which file and hook or class).

Any ideas?


I've tried to search inside all files in docroot, e.g.

$ grep -r "The URL of the redirect" .
(nothing)
$ grep -r "The URL of the" .
(returns everything apart of redirect, no matching placeholders found)
$ grep -r token modules/contrib/redirect/
modules/contrib/redirect/config/install/views.view.redirect.yml:          tokenize: false
modules/contrib/redirect/modules/redirect_404/config/install/views.view.redirect_404.yml:          tokenize: false
modules/contrib/redirect/modules/redirect_404/redirect_404.routing.yml:    _csrf_token: 'TRUE'
modules/contrib/redirect/src/EventSubscriber/RouteNormalizerRequestSubscriber.php:      // Strip off query parameters added by the route such as a CSRF token.
$ grep -r redirect modules/contrib/token/
modules/contrib/token/src/Controller/TokenCacheController.php:   * Clear caches and redirect back to the frontpage.
modules/contrib/token/src/Controller/TokenCacheController.php:    return $this->redirect('<front>');
$ find modules/contrib/redirect modules/contrib/token -name "*.tokens.inc"
modules/contrib/token/tests/modules/token_module_test/token_module_test.tokens.inc
modules/contrib/token/token.tokens.inc (Note: nothing here for redirect)

So basically I couldn't find the source which module is defining those. This can help me in order to find out, why some of them aren't working as expected.


The main reason I ask this, because I would expect for redirect URL such as /foo/XXX, to return XXX when using [redirect:url:args:last], but these tokens aren't populated at all.

هل كانت مفيدة؟

المحلول

As Clive mentioned, since Redirect is an entity, those tokens are automatically generated by the Token module's token.tokens.inc.

I suggest you read Custom Tokens in Drupal 8 to understand how they are declared & work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى drupal.stackexchange
scroll top