How to access entity from EntityReferenceItem?

by user2951257   Last Updated December 16, 2017 01:07 AM

I have the attached array below and need help figuring out how to access the 'entity' attribute that is under the protected "properties" array (see screenshot).

Entity Reference - Entity value

background: field_name is an entity reference field. I need to get the EntityReference so that I can call getTarget() to get the EntityAdapter and then call EntityAdapter->getValue().

I have tried the following but they all give errors. The idea is to get the EntityReference which is the 'entity' value. How can i do this?

$offset = $entity->get('field_name')->offsetGet(0)
$entityReference = $offset->get('entity') /* failed */
$entityReference = $offset->getProperties() /* failed */
$entityReference = $offset->getEntity() /* failed */
Tags : 8 entities hooks


Related Questions


Insert data into entity programmatically

Updated May 16, 2017 17:07 PM

How to create edit custom url for entity

Updated July 10, 2017 08:07 AM


How to get nid while inserting new node drupal 8

Updated January 04, 2018 13:07 PM