2

This question is already asked here, but the answer selected does not work for Drupal8.

Description: There is a content-type, which has field, referencing taxonomy term. The term is in "Content class" dictionary. This term is used in views to filter the right content for the view. When a link in the view is clicked, it opens the node. This is OK. So, it is needed pathauto to generate /Content class term/Content_title_name when this node is opened.

What did not work: [node:field_content_class:value]/[node:title]. This is not accepted, produces error: Path pattern is using the following invalid tokens: [node:field_content_class:value]

The accepted (by Drupal) pattern: [node:field_content_class]/[node:title] generates alias, containing only the [node:title] part. The first component is empty.

This is made to not create separate content-types for nodes with the same fields.

EDIT: The accepted answer works on a fresh copy of Drupal with language translation enabled. I continue to investigate the case with my production site.

1 Answer 1

5

A taxonomy field is referencing entities, it has no value property. See how to print value of a taxonomy field to headline with node.html.twig?

Converting this to a token pattern:

[node:field_content_class:entity:name]/[node:title]
3
  • Thank you. It looks like it should work as you propose. Appending :entity:name to the token definition did not produce error, but the resulting path aliases still contain only /[node:title] and the taxonomy term token remains empty. Additoinal details: the installation is multi-language and the taxonomy terms are translated. When the languages are switched, the reference field correctly switches its value (on the node page the translated taxonomy term appears). The field is required and the number of values is limited to 1.
    – A. Genchev
    Apr 22, 2021 at 0:07
  • 1
    Just checked the issue queue, translation of tokens seems to be fixed a long time ago. Even if it still was an issue it should show the untranslated term name.
    – 4uk4
    Apr 22, 2021 at 7:30
  • I have installed a fresh copy of Drupal and your answer works there, so I put accept mark on it, but I will continue debugging my full-of-data site where this does not work
    – A. Genchev
    Apr 22, 2021 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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