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).
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 */ $ entityReference = $ offset->getValue() /* failed */
The error message is: replace getValue() with any of the above
Call to a member function getValue() on null