A site I am working on has a content type called property with a large number of fields within where the data is brought in from a 3rd party API.

Currently we use pathauto for generating alias urls of our content and has admirably filled our needs, except for the property content type which has a number of conditions which can determine what its url is and I am unsure that pathauto can do what is required.

We are using Drupal 8, latest version.

A properties url will contain the location, the listing type (sale, rental, auction or new-home) and the title of the property in its url.

So for example, a property with title ABC which is been sold in henley would have a url along the lines of http://example.com/property-for-sale/henley/abc.

But a property xyz on auction in basingstoke would be along the lines of http://example.com/auctions/basingstoke/xyz

Is there a hook/module or Drupal way (Views?) of handling this please? IF I remember Drupal 7 had hook_url_inbound_alter but I cannot find this in the D8 API.

Any enlightenment would be appreciated.

Grateful Grasshopper/John


If your Location, Listing type, and title are Fields in your Content type you can use Pathauto Patterns options (/admin/config/search/path/patterns) to automatically generate the aliases from values in nodes.

You use tokens available for the content type to construct the pattern. You can browse through (a very long) list of tokens to find the one you're looking for. Maybe it would be something like:


  • Unfortunately I cannot guarantee that all the items are available on the content type and are subject to change if the 3rd party adjusts the API data. So I need to find a different way of doing this. Is it possible to write to the 'URL alias' field during the node->save() event? Doing it this way I can update the URL alias after doing a bunch of calculations/lookups ?
    – John Cogan
    Feb 14 '19 at 7:14
  • your answer combined with me doing a lookup and writing to a new field in the CT during the node->save will allow me to do this. Thanks @prkos
    – John Cogan
    Feb 14 '19 at 7:22
  • Yes, you can update it on node save with some custom code, Rules may help set up part of the procedure, it all depends on how you connect to the API. Saving the API info into CT is probably the best way, then letting Pathauto take it from there because you can set up the option about what happens to the old alias when a new one is created because a change occurred. You don't want the remote API mindlessly control your URL structure without proper care of redirects and similar. You can always hide the field you're using to store the path data so it's not shown on the node view.
    – prkos
    Feb 14 '19 at 15:52

Your Answer

