This allows for a token to a referenced node's path. Useful for things in pathauto like referenced node: /tree and referring node: /tree/blog/[title].

This could easily be modified to work with links and imagefield src as well, but I didn't want to test for those right now, so not sure if their $item arrays returns the same useful info.

Comments

aaron’s picture

it would be used like [field_refnode-path]/[title]

greggles’s picture

Status: Needs review » Needs work

There is some history to calling these things aliases - bookpathalias termpathalias etc. What do you think about calling these "alias" instead? See http://drupal.org/node/224243 for more motivation to name them consistently.

Also, instead of

<code>
+      $tokens['path'] = preg_match('@\<a href\="([^"]+)"\>@i', $item['view'], $matches) ? $matches[1] : '';

How about:

+      $tokens['path'] = url('user/'. $item['uid']);

I prefer not using a regex if possible and url seems more reliable and easier to maintain.

aaron’s picture

ah, whoops. there i go, making a mountain out of a molehill...

new patch in a bit...

aaron’s picture

Status: Needs work » Needs review
StatusFileSize
new2.76 KB

new patch attached.

also note this fixes the description of the noderef link as well, from "Formatted html link to the node." to read "Formatted html link to the referenced node.", which is a better description, and matches the userref link token.

thanks,
aaron

dww’s picture

Over at #246464-4: Add a path token for referenced nodes I just made the case and supplied a patch that does both "path" and "absolute_path" tokens for referenced nodes. This, however, is the even older issue (I just found it), and is also dealing with user references, too. Before I spend more time rerolling something, can I get an 'amen' from a token maintainer about the desire for both relative and absolute path tokens, and some agreement on what they should be called?

Thanks,
-Derek

dww’s picture

Status: Needs review » Needs work

In IRC, Eaton said he thought [path] should be used for the relative path on the site, and [url] should be the absolute URL. I just supplied a patch that provides this in the regular node case, over at #127613-7: Provide tokens for node url and path (i.e. absolute and relative alias respectively). Assuming that's going to land soon, we should probably re-work this patch to use the same naming conventions for consistency...

greggles’s picture

I'd really prefer to see these added to cck for 6.x (since token for cck in 6.x is handled within the cck modules themselves) and then backported to 5.x if necessary. The cck maintainers understand the cck data objects much better than I and find flaws that I won't.

dww’s picture

Title: Allow node (and user) referenced path aliases... » Provide tokens for referenced node (and user) url (absolute) and path alias (relative)
Project: Token » Content Construction Kit (CCK)
Version: 5.x-1.x-dev » 6.x-2.x-dev
Component: Code » nodereference.module

Sounds good to me... moved.

deviantintegral’s picture

Status: Needs work » Needs review
StatusFileSize
new3.11 KB

I've ported the previous patch to CCK's content.token.inc file. It's virtually identical to the above, but should provide a starting point. I've renamed the tokens as suggested as well.

yched’s picture

I won't test this but happily commit if someone sets RTBC.

dww’s picture

Ugh, I can't figure out how to get node reference tokens to work at all. However, I'm sure if I could, these would work. ;) The patch certainly didn't blowup my D6 test site, and looking at the code, it's doing exactly what it's supposed to. If someone can enlighten me about how to specify noderef tokens in the first place, I'll confirm it actually works. I'd set this to RTBC, but I have to save at least some credibility. ;)

deviantintegral’s picture

To test, I created two node types, one type to be referenced and one type containing a nodereference field. After creating a few nodes and filling in the node reference fields, I tested the token part by using the page_title module, since I was all ready working on it. I added "[field_page_reference-path] | [field_page_reference-url]" to the default title (field_page_reference was my field name).

If you have devel installed, you could probably test just by running php directly and calling token_replace().

--Andrew

dww’s picture

Status: Needs review » Reviewed & tested by the community

Ahh, [field_page_reference-path] was the magic syntax mojo I was missing. ;) Thanks. Ok, actually tested now, and confirmed that all tokens are working on both unaliased and aliased paths. As I said, RTBC. ;)

yched’s picture

Status: Reviewed & tested by the community » Fixed

OK, committed. Thanks !

deviantintegral’s picture

Now that this has been committed, what needs to be done to backport it to D5? Should it be in Token, replacing it's include file, or made to work in CCK's 5.x's -dev branch?

--Andrew

dww’s picture

Status: Fixed » Patch (to be ported)

A) @yched: Do you plan to commit to HEAD, too, or do y'all just periodically merge everything from DRUPAL-6--2 into HEAD?

B) @deviantintegral: CCK 5.x-* doesn't include the token support. In 5.x, token.module provides the CCK tokens, so this needs to turn back into a patch against D5 token_cck.inc.

Leaving this in the CCK queue for now until yched replies about (A), but setting to "patch (to be ported)" since that's true for both (A) and (B). ;)

yched’s picture

@dww : no, we 'periodically' merge.

dww’s picture

Project: Content Construction Kit (CCK) » Token
Version: 6.x-2.x-dev » 5.x-1.x-dev
Component: nodereference.module » Code

Ok then, moving back to the token queue.

deviantintegral’s picture

StatusFileSize
new6.38 KB

Sounds good - here's a patch against Token. Looks like Token's api changed a bit, so the $options array is now gone. This is literally a copy+paste+merge - I've only tested the nodereference stuff so far. Looks like some of content_token_values changed as well, but AFAIK it looks to do the same thing.

--Andrew

summit’s picture

Subscribing, greetings, Martijn

deviantintegral’s picture

Status: Patch (to be ported) » Needs review

Not sure what the current status of Token on D5 is (I no longer manage any Drupal 5 sites), but this really is needs review or won't fix :)

dave reid’s picture

Status: Needs review » Closed (duplicate)