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:
- Install cck, nodereference, pathauto, and subdomain
- Create a new content type of "Test"
- Create a new content type of "Subtest", and add a nodereference to "Test"
- Set pathauto for node type "Test" as "[subdomain]/[title-raw]"
- Set pathauto for node type "Subtest" as "[field_test-path]/[title-raw]"
- Create a new node of type "Test" titled "test1"
- 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
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | cck-nodereference-path-token.patch | 1.24 KB | pawel_r |
| #5 | 343537-cck-nodereference-path-token.patch | 1.22 KB | mrfelton |
| cck_nodereference_path_token.patch | 1.45 KB | duellj |
Comments
Comment #1
corneverbruggen commentedI totally agree. Have a similar problem, resulting from the same issue, and solved by the patch duellj provided.
Comment #2
finex commentedThe 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.
Comment #3
finex commentedI've succesfully applied this patch in another two websites and all is working fine!
Comment #4
jasom commentedPatch worked for me as well.
Comment #5
mrfelton commentedI 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).
Comment #6
finex commentedI've applied this patch again... about 50% of my Drupal website are using this patch :-)
Comment #7
pawel_r commented#5 - I had same problem with language prefixes, patch seems to be valid.
Comment #8
dave reidThe output of drupal_get_path_alias() is not trusted and needs to be escaped with check_plain().
Comment #9
pawel_r commentedLike this one?