I didn't find anything about this topic yet, so here we go:
Here is my scenario:
2 x Content Types:
1) Venue with a CCK Location field
2) Event with a CCK node reference field --> Venue
In Node Path Settings I'd like to be able to create a path for Event that includes the node reference CCK Location field from the Venue content type. Like what can be done using Views 2 and setting up relationships.
As far as I know, only the Referenced node ID and Referenced node title tokens are available to the pathauto module.
Perhaps a relationship could be created like this:
[field_venue_id-nid]#[location-city_0]/event
Which would allow for any relational tokens to also be added to the path. If not, the only other viable scenario that I can see is to add a location to the Events content type.
Comments
Comment #1
gregglesThis is not really about Pathauto, but about Tokens provided by other modules.
For what it's worth, I don't think it makes sense to create tokens for every field of a referenced node - the performance could get painful. Instead, I suggest some custom code in a token starterkit #437842: create a token starterkit module and documentation so people know how to use it.
Comment #2
andrewsuth commentedMaybe I'm wrong, but my scenario described above doesn't need new tokens for the modules; the tokens already exist. It's about creating a method to make a relationship to a referenced node so that the already existent tokens can be used in pathauto.
Eg.
[reference_node_id]#[description-raw]Where
[description-raw]already exists. As it stands,[description-raw]is currently inaccessible to pathauto because it's a token from a referenced node.I see this as being a very powerful feature for the module which would add a whole new level of flexibility, like what Relationships added to Views 2.
Comment #3
gregglesOK, then. Creating a relationship between tokens should be up to token module and is postponed for "token 2.0" does it's lazy loading of tokens.
Comment #4
andrewsuth commentedYou're right, Token would be the module for adding this feature.
I'm not familiar with the code behind Token but if you could give me any ideas of how this feature should be implemented I can see about getting a patch up for it.
Comment #5
shaneforsythe commentedsubscribe
Comment #6
Parkes Design commentedhey andrewsuth, I was after similar functionality as well and came up with a long winded codeless way of doing it.
I used the rules module http://drupal.org/project/rules to load the reference node within the child node(action). Once I did this then I created another action to set content title. Now "Replacement patterns for Referenced content" within the token settings is available, where you can grab the required field from the referred content and populate the content title pattern.
Maybe this process can help you with your pathauto situation?
Anyway I'm subscribing to this because the functionality would be awesome without the rules workaround.
Comment #7
ISPTraderChris commentedI'm trying to expose tokens from another content-type via nodereference. I was hoping to do this with a bit of code within a Computed Field.
I can load the reference node via node_load($node->field_nodereference[0]['nid']), but I'm not sure what to then do with it so that the Token module can 'see' it and resolve its tokens.
Any pointers would be greatly appreciated.
Comment #8
BarisW commentedI have the same problem. Would love to have Token inherit all fields from its parent node(s).
Subscribing!
Comment #9
drupov commentedsubscribe
Comment #10
petasques commentedsubscribe!
Comment #11
bessone commentedsubscribe
Comment #12
drupov commentedHas anyone tried to use the Custom Tokens module for it: http://drupal.org/project/token_custom ?
Comment #13
patcon commentedVery interested in this! Here's my potential application, that others might find useful too:
I have a lot of simple text nodes that need updating every year, and it would be nice if this was streamlined for my client so that all they had to do was change the node reference field, and a separate set of tokens would be pulled into the template.
Here'd the ideal scenario:
1. I create a content type called "Dynamic template", with just a body and a node reference field that can reference any other node that might have info I could extract.
2. Create different "Dynamic template" nodes, with titles like "User agreement", "Competition information", etc... whatever might have info that needs to be kept current by updating in a fill-in-the-blank sort of way. For the node ref, link to the node with the data to populate the given template.
* In my case, I have a content type called "Competition year", that is filled with all the information about the current year (used for many things). It has fields for the different deadlines, competition dates, number of teams/participants & average scores (filled in after the event)
3. It would be perfect if I could link the current year, and simply compose my template document, using tokens that were taken from the fields of the node referenced node. So the tokens would need to be constant, like
[noderef_0-title]in reference to the referenced node's title.Yes, this could be done hackishly with custom theming of views, having all the text in a *.tpl.php file and pulling all the info from one row/node. The problem is that this would be difficult to edit for my client (they'd need to edit the tpl.php file), and also overly confusing to change the fill-in-the-blank data, ie. year (they'd need to navigate through views filters). The proposed way would make it so that they could edit right in the body, and update the template by selecting a new node from an autoselecting node reference field. MUCH EASIER. This would also make site updates simpler, since all the links would remain the same. I imagine this might help with SEO too?
Any thoughts guys? Could this help anyone else out?
Comment #14
patcon commentedAlso, might be able to do this with computed fields, having those fields populate with info from the referenced node, and then use THEIR tokens. But this would be much less versatile, and I'd need a content type for each type of template, since each would have it's own blanks that need filling in.
Comment #15
drupov commentedI'm coming back to #12:
If you have a node reference structure Continent -> Country -> City and you want to have the name of the continent a city belongs to displayed by a token, you could write a custom token with following code:
This loads the ID of the country, then loads the node data using that id and does pretty much the same for the continent. At the end it returns the title of the continent.
Comment #16
patcon commentedIn reference to my #13 comment (and idea sparked by #15 -- thanks mitkoru!), I'm looking into the possibility of using Custom tokens for my situation:
#662316: Custom token sets: multiple tokens from one PHP function
Comment #17
petasques commentedIt's not the killer solution, but it worked for me, I discovered activating the Token Actions modules that trying to create a new action (/admin/settings/actions --> admin/settings/actions/configure/246fdc2a4672eb371d05b48b2a7cb51e ) "Redirect to a tokenized URL" you can see all placeholders for all your referenced content-type, and there is was my [field_myfieldname-title-raw] of the referenced content type.
Comment #18
jackrabbitsf commentedI have figured out a way of using computed field with a query inside the php to basically get any field from any content type to appear in any other content type (parent or otherwise)- like belows for instance- where i get the province from the parent node by linking the node-reference to the nid on the parent and then getting the proper location id (lid)
$node_field[0]['value'] = db_result(db_query(
"select a.province ref_state from location a right join
(SELECT lid FROM location_instance where nid =
(SELECT distinct field_band_ref_nid from content_type_embedded_video where nid=$node->nid)) b on a.lid = b.lid"
));
It works for creating the value i want in the content, but i cannot use proximity searches since it is a computed field and the child content still technically has no location... i'm still trying o figure that out. Maybe this helps someone????
Comment #19
TripleEmcoder commentedSubscribing.
Comment #20
dave reidThis would have to be provided by CCK.module, which implements its own tokens in D6.
Comment #21
karens commentedWe're basically not adding new features to CCK for D6 this late in the D6 cycle. Everything is changed in D7 anyway with fields in core, so any new features would have a short life, too short to be worth the effort. There are some suggested solutions above, that will probably have to do. Someone can always create a new module to provide new features if someone wants to write and maintain it.
Comment #22
shushu commentedParkes Design - Thanks for the tip !
I don't see it as a workaround, this is how things need to be done.
It just shows the strength of Rules.
(I had to say it...) Rules Rules !
Comment #23
magnus commentedThis is how I solved this issue with Custom Tokens: http://drupal.org/node/784808#comment-2924708
Comment #24
jasom commentedI found working CCK token patch here http://drupal.org/node/343537
Comment #25
mxtI tried some of the solutions suggested above, but the only one that worked in my case was that proposed by MRU in # 15. I think using the Custom Tokens module is the most simple, flexible and fast.
In particular:
MXT
Comment #26
itserich commentedI installed custom token and it looks like I need to insert some php related to cck filelds to create the token.
Is there a way to figure out the variables for the different fields?
Tokens for CCK fields seems a popular request but I don't see much documentation.
Comment #27
patcon commentedthe dpm function from the devel module is always a good place to start when you're looking for this sort of thing.
But your question is really better-suited to the Custom Token issue queue. Try starting here:
http://drupal.org/node/784808
Cheers :)
Comment #28
bramface commentedAndrew, how did you end up solving this problem? I have EXACTLY THE SAME SITUATION right now (we're making a Drupal version of zvents.com). We have two sticky points:
1) Getting the City and State out of the Venue and into the Event to create a URL Alias (your problem above).
2) Preventing Venue users from creating events linked to other venues.
If you are still subscribed to this thread (or if anyone else is who has done something like this and might consult), please contact me?
Thanks,
Bram