0

We have an Entity reference field on Basic Page content type that is set to Articles. The Articles content type has a field, field_category that is a taxonomy term.

What is the correct token to get the value of the field_category?

Basic Page:

  • field_articles -> entity reference to Article content type.

Article page:

  • field_category -> taxonomy term field.

Goal:

  • Return the field_category label from the Article node that is set on the Basic Page

Example:

Basic Page -> page1(nid=0)

  1. field_articles = articlePage1 (target_id = 1)

Article page -> ArticlePage1 (nid = 1)

  1. field_category = Cloud (tid = 10)

Token should return Cloud for page1.

We tried the following but it didn't work.

[node:field_articles:entity:field_category] 

1 Answer 1

0

You try use hook_tokens

 /** * Implements hook_tokens(). */ function mymodule_tokens($type, $tokens, array $data, array $options, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) { $replacements = array(); // $type is token type if ($type == 'node' && !empty($data['node'])) { foreach ($tokens as $name => $original) { // to do $replacements[$original] ='xxx'; } } return $replacements; } 

See more api hook_tokens()

1
  • the custom token has been working as expected. Commented Aug 23, 2018 at 15:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.