0

I have a node that has a parent_field (entity reference) that if left empty, that node is a parent. If parent_field has data (ie the nodes parent node name) then I can easily add pathauto in there like so:

[node:parent_field]/[node:title]

However, I would like to be able to select a child as a parent and have pathauto gather this in to the path. Basically getting the parent and child entity reference:

[node:parent_field]/[node:parent_field(child of parent???)]/[node:title]

However, in pathauto (entity tokens included), I don't see how to grab this.

Thoughts?

EDIT:

I was able to do this by chaining entities. @Clive in the comments and a post online helped me figure this out.

In the end my pathauto looks like so:

program/[node:field_parent_program:entity:field_parent_program:entity:title]/[node:field_parent_program]/[node:title]
  • 2
    I don't understand how you want to fetch a child and how that makes sense, but you can always implement your own tokens using hook_token_info() + hook_tokens() and then you're only limited by what you can do with PHP. – Berdir Dec 13 '18 at 21:30
  • Thanks @Berdir. Basically one Entity Reference field. The child knows its parent, so how can the grandchild know it's grandparent. – jasonflaherty Dec 13 '18 at 21:43
  • 2
    The child knows its parent It doesn't though - all it knows is that it has a referred entity, it doesn't know that it's supposed to be a parent to a child. As far as the system is concerned these could just as easily be sibling relationships or something else. You'll either need custom tokens as @Berdir suggested, or perhaps a rethink to use the taxonomy term entity type instead, which has the concept of lineage you're looking for baked right in – Clive Dec 13 '18 at 22:07
  • Or in a pinch something like this might work: [node:parent_field:entity:parent_field]. But be careful using nodes for this, it'll be easy enough to end up in an "I'm my own Grandpa" type of situation :) – Clive Dec 13 '18 at 22:15
  • @Clive : that seemed to work just great. I found a post on chaining entities. Worked just how I needed it to. flocondetoile.fr/blog/token-and-chained-entities-drupal-8 – jasonflaherty Dec 14 '18 at 17:42

Your Answer

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

Browse other questions tagged or ask your own question.