Wednesday, 15 July 2015

Drupal 7 using Node Nid to get Entity Data

Ok I'm using this blog as a bit of a code bin.

Here's a quick sample of code if you need to get some Entity data from within - you'll need to add protection against any data not being available.

 * Implements template_preprocess_node(&$variables)

function rcnjobs_preprocess_node(&$variables) {
 $nid = $variables['nid'];

  $this_node = node_load($nid);
  $this_node_wrapper = entity_metadata_wrapper('node', $this_node);
  $recruiter = $this_node_wrapper->field_recruiter_reference->value();
  $recruiter_name = $recruiter->name;

  $location_tid_info = $this_node_wrapper->field_job_location->value();

  $location = $location_tid_info[0]->name;


No comments: