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).
I am using the Viewfield module
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?
mytheme_preprocess_viewfield_item(&vars) { $element = $vars['element']; $results = $element['#content']['#view']->result; foreach($results as $row) { $entity = $row->_entity $offset = $entity->get('field_name')->offsetGet(0) kint($entity->get($video_field_name)) /* result of screenshot */ $entityReference = $offset->get('entity') /* failed */ $entityReference = $offset->getProperties() /* failed */ $entityReference = $offset->getEntity() /* failed */ $entityReference = $offset->getValue() /* failed */ }//end foreach }//end theme_preprocesss
The error message is: replace getValue() with any of the above
Call to a member function getValue() on null
Sponsored by SupremePR
