3

I am trying to find the correct tokens to use for a Pathauto pattern in Drupal 8.

In Drupal 7, I have a Pathauto module pattern that creates a URL alias with a node's term and parent term.

So if the node had a Term reference of Health -> Diet. The URL would be health/diet/node-title.

The pattern to generate this is [node:field-topic:0:parents:join-path]/[node:field-topic:0]/[node:title]

Note the :0 is because the Term reference field allows multiple values.

4
  • Did you try node:field-topic:0:entity? Tokens behave like accessing fields in the API and entity query, they require that you specifiy :entity: to access the referenced entity.
    – Berdir
    Commented Jan 5, 2017 at 20:43
  • It doesn't like that either unfortunately. I found this which suggests the functionality hasn't been implemented yet drupal.org/node/2821810 Commented Jan 5, 2017 at 23:41
  • That's just another wrong way of using the token. I only just noticed now that you have field-topic, but it should be field_topic, that might fix it.
    – Berdir
    Commented Jan 6, 2017 at 0:02
  • Yeah I've tried both variations - and _ Commented Jan 6, 2017 at 0:06

1 Answer 1

10

I just tested the tokens that I suggested in the comments with field_tags on articles and it works perfectly, no idea what your problem is, make sure you use the latest versions of pathauto and token.

Token: /articles/[node:field_tags:0:entity:parents:join-path]/[node:field_tags:0:entity]/[node:title]

Tag hierachy: A > B > C

Alias for an article tagged with C: /articles/a/b/c/pathauto-test

1
  • Thanks! Not even sure what I had wrong earlier but that pattern is working. Commented Jan 7, 2017 at 5:20

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.