Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7 - Getting referenced entities with a node_load()

Tags:

drupal-7

Within the node template, the $node object has the entity next to each 'target_id' value, making things nice and easy.

However if I load a node programatically (via node_load) it only has the target_id value, no entity is attached. So I'm having to do a lot of manual load_taxonomy(target_id) to get this.

So clearly Drupal at somepoint in the render pipe-line is doing this automatically, but Is there a function I could be calling to do it?

Thanks!

like image 250
RoyalFool Avatar asked Oct 08 '22 14:10

RoyalFool


1 Answers

Try this:

if ($node = node_load($node_id)) 
{
    $view = node_view($node);
}

http://api.drupal.org/api/drupal/modules!node!node.module/function/node_view/7

like image 119
druf Avatar answered Oct 12 '22 10:10

druf