Using url() instead of drupal_get_path_alias() for the nodereference path token causes problems when used in conjunction with the subdomain module. The subdomain module provides subdomain pathauto support by replacing a prefix (defaults to "~") with an appropriate subdomain. Using url() to get the path of a referenced node if that node is set to use a subdomain will return the wrong path for the referenced node.

To replicate this issue:

  1. Install cck, nodereference, pathauto, and subdomain
  2. Create a new content type of "Test"
  3. Create a new content type of "Subtest", and add a nodereference to "Test"
  4. Set pathauto for node type "Test" as "[subdomain]/[title-raw]"
  5. Set pathauto for node type "Subtest" as "[field_test-path]/[title-raw]"
  6. Create a new node of type "Test" titled "test1"
  7. Create a new node of type "Subtest" titled "subtest1"

The node "test1" will be given the url alias of "~test1" and will be rewritten to "http://test.test.com/test1" (given the base url of test.com).
The expected rewrite behavior for "subtest1" would be the url alias of "~test1/subtest1" and would be rewritten to "http://test.test.com/test1/subtest1". Instead, "subtest1" is given the url alias of "http:/test.test.com/test1/subtest1" and will be rewritten to "test.com/http%3A/test.test.com/test1/subtest1". Obviously this isn't the desired result.

This can be easily solved by using drupal_get_path_alias() instead of url(). If you look at pathauto.module, it uses drupal_get_path_alias() to set the termalias. I would argue that the nodereference path token should be renamed to "alias" to match pathauto, but the supplied patch only changes url() to drupal_get_path_alias(). It also makes a related change for the userreference path token.

Quite the long explanation for a two line patch, I know, but I hopefully the explanation was enlightening :).

Thanks,
Jon Duell

Comments

corneverbruggen’s picture

I totally agree. Have a similar problem, resulting from the same issue, and solved by the patch duellj provided.

finex’s picture

The patch is fine. Moreover is useful not only when you've subdomanis, but even if you want to have a hierarchy of nodes with more node references.

I've manually applied the patch to the 6.x-2.6 version and it works perfectly.

I really think that this is the right way this token should work.

finex’s picture

Version: 6.x-2.1 » 6.x-2.7

I've succesfully applied this patch in another two websites and all is working fine!

jasom’s picture

Patch worked for me as well.

mrfelton’s picture

StatusFileSize
new1.22 KB

I have a similar issue which is also resolved by this patch.

Two content types:
Parent node
Child node

There are two languages on the site, but both of the above content types are language neutral.

If you are on the default version of the site (no path prefix) and you create a Child node referencing a Parent node with nodereference, the alias of the child come out to /parentpath/nodetitle which is correct.

If you are on the /en version of the site and do the same thing, the path ends up as en/parentpath/nodetitle which is incorrect as it has the path prefix hardcoded into the alias. Pathauto then adds the prefix on making it en/en/parentpath/nodetitle. Incorrect.

This patch resolves this ensuring that the prefix does not get included in the alias.

Attached is an updated patch that confirms better to the drupal patch standards (from the module root).

finex’s picture

I've applied this patch again... about 50% of my Drupal website are using this patch :-)

pawel_r’s picture

#5 - I had same problem with language prefixes, patch seems to be valid.

dave reid’s picture

Status: Needs review » Needs work

The output of drupal_get_path_alias() is not trusted and needs to be escaped with check_plain().

pawel_r’s picture

StatusFileSize
new1.24 KB

Like this one?