Hi.

I am trying to port some working compute filed code from Drupal 5 to Drupal 6 and I'm almost there but I'm having some issues. I ran the code through deadwood and it converted the call to l() (which fixed one of my problems) and that was about it. I also added the precaution about accessing the nid in the compute section, but that can not be added to the display section, so I hope that is not the issue.

Essentially the compute field grabs a title in the compute section and uses that as the link title for the url, which is supposed to be nabbed in the display section. This compute field is then used within a views 2 view.

Here is the code for the compute section:

if (!$node->nid) {
  node_save($node);
}

// get the nid of the course
$course_nid = $node->field_course[0]['nid'];

// get the title from the NID
$result = db_query("SELECT field_course_name_value FROM {content_type_course} WHERE nid=%d", $course_nid);
$data = db_fetch_object($result);
$course_title = $data->{'field_course_name_value'};
$node_field[0]['value'] = $course_title;

Here is the code for the display section:

// get the nid from the URL
$course_nid = db_result(db_query("SELECT field_course_nid FROM {content_field_course} WHERE nid=%d", $node->nid));
	
$display = l($node_field_item['value'], 'node/' . $node->nid . $course_nid, array('attributes' => array('style' => 'color: #5b684d; font-weight: bold;')));

The link title displays correctly, but the link winds up being http://mysite.com/node/ for every node.

Thanks in advance,

Dan

Comments

webdrips’s picture

FYI, I used the php tags above to better highlight my code, but they were not included in either the compute or display sections.

Moonshine’s picture

A couple quick thoughts...

In the display code section I don't believe you'll have $node available as you are really in a display formatter function at that point. I believe the current nid is available in something like $element['#node']->nid though. I'm going from memory here , so you'll want to check it out. I could be wrong :) You can always display everything available by dumping get_defined_vars() if you want also.

My other thought is just that you have two nid variables getting concatenated in that l() function. $nid->nid . $course_nid I'd think you'll only want one there, likely course_nid once that's returning the right value.

mmjvb’s picture

Status: Active » Closed (outdated)