So let's say I have a basic page node.
I want to have this as an entity reference inside another content type - let's say an event content type.
So let's say that the event content has a url like baseurl.com/eventblahblahblah
When a user clicks over to the basic page that is the reference on node eventblahblahblah
, I want them to go to baseurl.com/eventblahblahblah/basicpagenodehere
- this needs to be the URL in the browser.
In addition, basicpagenodehere
can be in multiple references - so if basicpagenodehere
is also referenced by event2blah
, then I want it to also be located at the url baseurl.com/event2blah/basicpagenodehere
I'm looking at possibly doing this with alterRoute -
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection) {
}
}
But I'm not sure if this is the correct place to do it.
This link suggests maybe PathProcessor, but I don't think that would change the actual URL on the node at the end of processing:
How to alter and rewritte current path programmatically in Drupal 8?
So how do I set a dynamic URL based on referring node?