Skip to main content
16 votes
Accepted

Where is the the full tokens list for a site?

I see its one of those things that you once you know. Enable modules: Token Help (core) Navigate to the page: /admin/help/token.
BigEd's user avatar
  • 649
12 votes

How can i display tokens with html tags?

Try this one - $replacements[$original] = \Drupal\Core\Render\Markup::create("<b>Hello</b>"); Helpful links: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%...
Alex's user avatar
  • 348
9 votes
Accepted

How to get token of parent entity in paragraph?

There's nothing out of the box (see this issue for the details). Implementing your own token isn't too tricky. I haven't had a chance to test this but I'm pretty sure it'll work: function ...
Clive's user avatar
  • 167k
7 votes

How to programmatically create a custom token in a module

For Drupal 8, example using the node object: You can put tokens in your module at mymodule.tokens.inc using hook_token_info() to register them and hook_tokens() for the the replacement data. If you ...
oknate's user avatar
  • 14.3k
6 votes

How to attach token in a custom form field

token.module has various examples, for example this: // Add the token tree UI. $form['email']['token_tree'] = array( '#theme' => 'token_tree_link', '#token_types' => array('user'), '#...
Berdir's user avatar
  • 83.3k
6 votes
Accepted

Token get node NID

[current-page:url:unaliased:args:value:1] is the way to get the node ID from the URL with the token module. Source. Glad it helped you out sisko. Cheers! Thank you.
danuddara's user avatar
  • 478
5 votes

How to programmatically create a custom token in a module

For Drupal 8 // We need to include the needed class for tokens. use Drupal\Core\Render\BubbleableMetadata; /** * Implements hook_token_info(). */ function modulename_token_info() { $info = ...
Karthikeyan Manivasagam's user avatar
5 votes

Custom formatting of tokens for date fields

The Token module added direct support for datetime and daterange fields in December 2016. See https://www.drupal.org/project/token/issues/2786181. You should be able to use something like [node:...
Brian's user avatar
  • 1,082
5 votes
Accepted

Token does not return full dynamic path to Media Image URL

Would you believe: node -> media field -> media entity -> image field -> image style -> url Makes sense, right? (I mean, it makes sense if you understand core Media and Entity ...
hotwebmatter's user avatar
  • 2,112
4 votes

How to attach token in a custom form field

This is a copy from the "token.module". function token_theme() { $info['token_tree_link'] = [ 'variables' => [ 'token_types' => [], 'global_types' => TRUE, 'click_insert' =&...
Calar's user avatar
  • 143
4 votes
Accepted

hook_tokens_alter() not applying to [user:one-time-login-url] Token

You cannot alter it because that token is not returned from user_tokens(). You get that token only with code similar to the following one. $text_with_tokens_replaced = token_replace($text, $variables,...
apaderno's user avatar
  • 97.5k
4 votes

Use a file token for directory path when uploading a file via core file upload field?

In core this is not possible, because the file widget sets the #upload_location when it builds the form element. You need a module, for example File (Field) Paths. This module sets a temp path in #...
4uk4's user avatar
  • 100k
4 votes

Is it possible to use tokens in a menu link in Drupal8?

No, you cannot use tokens in menus out of the box. Here are some options: Use Views to create the link. This won't give you a menu, but you can make a block in Views and use that as a menu. You ...
Patrick Kenny's user avatar
4 votes
Accepted

Programmatically use token filter

Data about the node needed to be supplied as a parameter to the replace method. It worked once I used $node = \Drupal::routeMatch()->getParameter('node'); $vars['label'] = $token->replace($vars[...
Amy's user avatar
  • 5,718
4 votes

How to get token of parent entity in paragraph?

So with the newest version of Drupal 8 and Paragraphs, this is possible. Looking at the tokens on /admin/help/token, there is a [paragraph:parent_entity] under the paragraphs section which is exactly ...
Klaus Haukenstein's user avatar
4 votes
Accepted

What is a "link template" in a token?

Link templates are defined in the entity class. For webform_submission: * links = { * "canonical" = "/admin/structure/webform/manage/{webform}/submission/{webform_submission}", * "access-...
4uk4's user avatar
  • 100k
3 votes
Accepted

Is there a way to render a node with view mode via token?

So the question is how to insert something like [node:5:teaser] into a formatted text area and get the teaser view of node 5. This can be done with a combination of modules: Token Filter (D7,D8) ...
geek-merlin's user avatar
3 votes

clearing cache to call hooks in .module file

Short This is wrong use of tokens, it can never work. Long So what you are doing is incorrect usage of tokens. The idea with tokens, is that you have some data object, like a Node, a User etc and ...
googletorp's user avatar
  • 35.4k
3 votes
Accepted

Views: add (link to file field) to image field

First add the "Content:File" field Check "Exclude from display" (hidden) Under "Formatter" select "URL to file" Then add your Image field and uncheck "Link this field to the original piece of content" ...
Varshith's user avatar
  • 731
3 votes

modify date token in View to extract only year?

Steps to get the just the year for Delivery Date field Navigate to /admin/config/regional/date-time/formats page. Click on Add Format button (/admin/config/regional/date-time/formats/add) In the ...
Nitesh Sethia's user avatar
3 votes

Are user browser information and ip address available as tokens in Rules?

Use [current-user:ip-address] token for IP address of the current user. For browser related token you have generate it using token_generate API. function token_generate use to generates ...
Nikhil Banait's user avatar
3 votes

How to use token as a filter value in views

Use Contextual Filters instead of Filter Criteria. In Drupal 8, at the time of writing this, you also have to install the views_argument_token module. When adding a contextual filter, at the pop up ...
Francisco Luz's user avatar
3 votes
Accepted

Making File Size visible to anonymous users

Permission should be given for that file type in case of anonymous user. Because if size is visible to authenticated user and not to anonymous user, then it must be a permission issue.
Sugandh Khanna's user avatar
3 votes
Accepted

What is the purpose of the "token" custom display setting?

As Neograph734 commented, it allows you to change the output of field tokens without actually changing the default display of the field. You can find more information here: https://www.drupal.org/node/...
kufeiko's user avatar
  • 435
3 votes
Accepted

Pathauto tokens for taxonomy terms except root

The default tokens won't allow you to do this, but the only thing you're missing I think is an array token that removes the first element, I'd call it "tail". See token_token_info(), which defines for ...
Berdir's user avatar
  • 83.3k
3 votes
Accepted

What is the [random:hash:?] token?

It's a token for generating a random string. When you look into the implementation, you can see it's the result of hashing 55 random bytes with your selected hashing algorithm (the ? part of random:...
Shawn Conn's user avatar
  • 26.9k
3 votes

How to set up a text format that replaces the tokens?

Token Filter is a very simple module to make token values available as an input filter. This doesn't mean that all tokens will work in every location. For example, if you use a [node:field_foo] token ...
Shamsher Alam's user avatar
3 votes
Accepted

Metatag images don't work anymore after updating

This issue is documented here : https://www.drupal.org/project/metatag/issues/2994433 For the moment (21/09/18), there are two solutions : add :entity:url at the end of the token downgrade to ...
Xoclaf's user avatar
  • 313
3 votes

How to display a token in plain text (without link)?

I'm might be late to the game but after way too long, I was able to get a Taxonomy Term without a link using this. I needed this in a hidden field. [webform_submission:source-entity:...
n8tron's user avatar
  • 41
3 votes
Accepted

Using node values in a custom token

Creating custom tokens for nodes is fairly straightforward, Drupal provides core hooks to define your own. Here is an example from a project I just completed in a small custom module: /** * ...
Kevin's user avatar
  • 27.9k

Only top scored, non community-wiki answers of a minimum length are eligible