Hi,
I am wondering how to reference a CCK field from a different content type in the drupal 7 version of computed field?
I used the example code below in my old drupal 6 website and it worked great. I have just been playing with drupal 7 and am not sure how to duplicate this code for the new system. Would anyone be able to show me how to translate this code to work with the new way drupal sets up the db?
$node_field[0]['value'] = db_result(db_query("SELECT field_phonenumber_value FROM content_type_content_enrollment_application WHERE nid=%d",$node->field_application[0][nid]));
Comments
Comment #1
stephen verdant commentedDo you need to use a database query instead of loading the other content-type node? Something like...
// Get the node you need information from based on the node_reference
$application = node_load($entity->field_application['und'][0]['nid']);
// set the computed field... pseudo code, you'll likely need to tweak
$entity_field[0]['value'] = $application->field_phonenumber_value['und'][0]['value'];
pieces from my code (working) that I twisted into the above code:
$parent = node_load($entity->field_parent_direct['und'][0]['nid']);
$parent->type == 'feature'
$entity_field[0]['value'] = $entity->field_parent_direct['und'][0]['nid'];
Comment #2
colanComment #3
ruess commentedHi all,
Sorry to open this back up again, yet I figured better to reopen than to create another issue. This code posted by stephen isn't working for me. I'm wondering if anyone can confirm that this code works in Drupal 7 or if there's a different example to follow.
Here's another similar example I've found from Drupal 6 and wanted to know if Drupal 7 changes this in any way?:
"Suppose you have 2 nodes; node1 has the field you want and node2 has a nodereference field pointing to node1.
"
From: http://drupal.org/node/290443#comment-1822960
Basically, I want to pull in a field from a node that is referenced on the same node in a node-reference field, but am getting nothing when I try (as well as a NULL in my DB)
Thanks much
Comment #4
colanThere is no node object in D7. Please read the documentation.
Comment #6
chrisdomingo commentedHello. Before i've written this, i've tried dissecting some of the codes in the snippet, however, being so noob at this, i've resorted to seek some help.
I have two content types. The first content type i named "equipment". It contains several fields pertaining to the characteristics of the equipment (i.e. property number, serial number, kind of equipment, date purchased, description of the equipment). Also, i have another content type called "Issue ARE" (acknowledgement reciept of equipment). The content type "Issue ARE" has a node reference to the content type "equipment", but i also want some of the fields of "equipment" be automatically included in the content type of "Issue ARE". These fields are "field_property_number", "field_serial_number" and "field_date_purchased". The counterpart of these fields in the "Issue ARE" are "field_are_property_number", "field_are_serial_number" and "field_are_date_purchased". I am using Drupal 7.
I am currently looking at computed fields to achieve this, but i need some help with the syntax. Can someone please give me an example for at least one of the fields?.. thank you very much :)
From the post of stephen in #1,
$application = node_load($entity->field_application['und'][0]['nid']);
$entity_field[0]['value'] = $application->field_phonenumber_value['und'][0]['value'];
from this, i assume that "field_application" is the field where the value is to be referenced, but what is the "field_phonenumber_value".. this is the part that i am quite confused...
if i am to write my code based on the example for field_property_number,
$application = node_load($entity->field_property_number['und'][0]['nid']);
$entity_field[0]['value'] = $application->????????['und'][0]['value'];
please help...
Comment #7
pyvarlet commentedHi Christodomingo,
Sorry I can't help you, because I have the same problem.
I'd like just to know If you got the solution, and how you solved it?
Regards
Pierre