Wednesday, February 6, 2013

Get Drupal 7 image field url in Computed fields

Demo:


<?php

 $node = menu_get_object();

 $image = array_pop(field_get_items($entity_type, $entity, 'field_image'));

 $fid = $image['fid'];

 $url =file_create_url(file_load($fid)->uri);

?>

Notice array_pop still returns an array and we should use file_load to load the file as a node, finally use file_create_url


No comments:

Post a Comment