I'm needing to get the title of a referenced node from within its parent so I can use autonodetitles module. Since Token module isn't working for fields in D7, I'm trying to do this by pulling fields out of the $node object. Here's the field I'm interested in, at $node->field_cal_event_parent
[field_cal_event_parent] => Array
(
[und] => Array
(
[0] => Array
(
[nid] => 59 //CAN GET THIS VALUE
[access] => 1
[node] => stdClass Object
(
[nid] => 59
[vid] => 59
[type] => production_external_
[language] => und
[title] => Comedy Club //CANNOT GET THIS VALUE
[uid] => 1
[status] => 1
[created] => 1307347398
[changed] => 1307348726
[comment] => 1
[promote] => 0
[sticky] => 0
[tnid] => 0
[translate] => 0
[uri] => Array
(
[path] => node/59
[options] => Array
(
[entity_type] => node
[entity] => stdClass Object
*RECURSION*
)
)
)
)
)
)
So the problem is that although I can get as far as the referenced node's nid using
$node->field_cal_event_parent['und'][0]['nid'];
I can't find the syntax for going one level deeper and getting the referenced node's title field.
While this code will work, it feels that I shouldn't need to load the referenced node just to get the title field:
$mynid = $node->field_cal_event_parent['und'][0]['nid'];
$mynode = node_load($mynid);
print $mynode->title;
Is there an easier way?
thanks
Comment | File | Size | Author |
---|---|---|---|
#7 | 1192504-7-token_support.patch | 1.3 KB | Bevan |
#7 | Feedback-1.png | 226.92 KB | Bevan |
#4 | hook_token_info-2.patch | 1.14 KB | Everett Zufelt |
#2 | node_reference_token_info.patch | 1.11 KB | Everett Zufelt |
Comments
Comment #1
Everett Zufelt CreditAttribution: Everett Zufelt commentedI would also like to use a token to access the node title. I have a field:
'field_name;
Comment #2
Everett Zufelt CreditAttribution: Everett Zufelt commentedHere is a first pass at node_reference_token_info() It is not working but I thought I'd upload it in case someone else wishes to continue where I left off.
Comment #3
Everett Zufelt CreditAttribution: Everett Zufelt commentedWill require token module patch at #691078-320: Field tokens
Comment #4
Everett Zufelt CreditAttribution: Everett Zufelt commentedThis seems to be working in part. I can access the node reference with [node:field-name] You will need the Field Token patch along with this patch.
Comment #5
Everett Zufelt CreditAttribution: Everett Zufelt commentedRemoving tag
Comment #6
andypostWhat it means? (++)
Powered by Dreditor.
Comment #7
Bevan CreditAttribution: Bevan commentedThe patch makes node-reference fields appear in the Token UI's "Nodes" section. E.g.
[node:field-contact]
where "contact
" is a node-reference field. In addition to this, a new section in the UI called "Node references" is created, which does not make sense in the context of a node-type settings form. This appears to be because of the extraneous plus character ("+") in the patch from comment #4. This character was noted in comment #6.I removed the extra character from
node_references.module
and the "Node references" section disappeared.I am still not sure how the
[node:field-contact:field]
and[node:field-values:?]
tokens and sub-tokenswould be useful or what data they expose.The attached annotated screenshot notes this same information.
The attached patch is the same as #4 but with the extra plus character removed.
I was able to use this patch to use the title of a referenced node as a token in an automatice nodetitle.
Comment #9
emackn CreditAttribution: emackn commentedI think at a bare minimum, it would be a big step to just provide the Id's for the items being referenced. There is a token_function module, http://drupal.org/project/token_function , that you could use then pass those values into and process those into whatever info you needed.
Comment #10
emackn CreditAttribution: emackn commentedEverett,
which field token patch are you referring to?
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commented#7: 1192504-7-token_support.patch queued for re-testing.
Comment #13
andypostpatch should be done from root of module - a/references
Comment #14
andypostentity module has entity_tokens sub-module whick mostly works except pathauto (returned url have all '/' are removed)
Related issue #691078: Field tokens
Comment #15
stano.lacko CreditAttribution: stano.lacko commentedBasic token fields are implemented in current token core module, but I need to add token for nid, as argument to Viewfield module of referenced field.
Current sulution [node:field-someone] return plain title of referenced module, but I need to get a NID of referenced module. Current version of Node references doesn't implement token for nid, or value.
So as original post of this issue, current situation is differencent, i dont'n need title but nid (original want title except of nid) ;-)
Comment #16
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #17
andypostThis module require token support, please don't change status