1

I installed Pathauto, Tokens and Entity API module in Drupal 8 and I have been unable to create a pattern that would allow parent taxonomies and then the final node for content type pages. In Drupal 7 the entity API module would add the extra tokens I need but it does not seem to work for Drupal 8.

For Drupal 8 the token [term:parents:join-path] works but it is only usable for taxonomy type pages and not content type pages.

If anybody can help me,I would greatly appreciate it.

1

This is being worked on, see https://www.drupal.org/node/2493559 and https://www.drupal.org/node/2621598.

In the meantime, you need a bit of custom code to connect the dots. You need to implement hook_token_info()to define a token on nodes for your field with type term. You can also switch the type of the generated field token to term. The second part is a hook_tokens() implementation that forwards [node:yourtokenname:...].

It's similar to what node_tokens() does with node:author:name for example, which forwards the part after author to the user token generation:

if ($term_tokens = $token_service->findWithPrefix($tokens, 'yourtokenname')) {
  $replacements += $token_service->generate('term', $term_tokens, array('term' => $node->field_yourfieldname->entity), $options, $bubbleable_metadata);
}
| improve this answer | |
  • where does this hook go? in the .template inside the themes folder? or do i need to create a custom module and import the token module files? – blu May 16 '16 at 17:32
  • You don't need to import any files, but yes, you need a custom module. A few special hooks can be implemented in themes too (in .theme, not .template, that doesn't exist) but in general, you need a module. – Berdir May 16 '16 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.