2

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.

  • 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 Jan 5 '17 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 – Scott Anderson Jan 5 '17 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 Jan 6 '17 at 0:02
  • Yeah I've tried both variations - and _ – Scott Anderson Jan 6 '17 at 0:06
6

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

  • Thanks! Not even sure what I had wrong earlier but that pattern is working. – Scott Anderson Jan 7 '17 at 5:20

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.