On my Drupal 7 website, I have used Entity Construction Kit to create an entity that contains two fields: field_body_image and field_image_position.

This entity is then attached to a node.

I want to be able to access the value of field_image_position from inside field_body_image. How can I do this?

Steps I have taken to solve the problem:

I know that if you have the fields placed directly on the node (ie. so not using ECK) you can use field_get_items

However, this doesn't seem to work when ECK is involved.

Here is the code I am using in my template.php file

function [THEMENAME]_field__field_body_image(&$variables) {

    //Load the value of field_image_position
    $field_image_positon = field_get_items('node', $variables['element']['#object'], 'field_image_position');
    $image_positon       = $field_image_position['und'][0]['value'];

if ($image_positon == 'image_position_bottom' ) {
print 'Successful' //This is just a test to see if it works, the actual code will be different
 However, this does not work.

If I use Devel and do:

function [THEMENAME]_field__field_body_image(&$variables) {

Then I can see field_image_position located in the following:




So how can I access it?

(using $field_image_positon = field_get_items('node', $variables['element']['#items'], 'field_image_position'); causes a White screen of Death. )

1 Answer 1


You mentioned you are using ECK to create a new entity, whereas in your code, you are using 'node' instead of the machine name of your entity.

I am referring to the line:

$field_image_positon = field_get_items('node', $variables['element']['#object'], 'field_image_position');

Change node in this line to your_entity_machine_name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.