The User profile for my site contains the Entity Reference field 'Parent' which points to another User.

I have the entityreference_backreference module enabled on my Drupal 7 site. I need to programmatically access the values of the properties added to the user entity by the entityreference_backreference module, so that for User A, I can identify all other Users which point to A via the 'Parent' EntityReference field.

If I do the following

$wrapper = entity_metadata_wrapper("user",$some_user);

I can see that that an entry for the entityreference_backreference field field_parent_user_eb is available in the getPropertyInfo() output. So the property does exist.

However, if I do


it comes back with "data = null".

Also if I just try to access $some_user->field_parent_user_eb that also gives a null result.

It looks like the property is never being set.

What am I doing wrong? I can see that there is a "getter callback" defined for the field_parent_user_eb property, which is set to entityreference_backreference_related_entities, but I can't see how I can use this.

Any help much appreciated!


OK this was my ignorance of how to use Entity Metadata Wrappers. The way to get the value of the field_parent_user_eb field is

$wrapper = entity_metadata_wrapper("user",$some_user);
$value = $wrapper->field_parent_user_eb->value();

$value contains an array of entities which (back) reference the original $some_user.

I should have read https://www.drupal.org/docs/7/api/entity-api/entity-metadata-wrappers before posting.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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