foreach ($view->result as $key => $result) {
    $entity_id = reset($result);
  // ...
  }

This is not an assumption we can do. Let's look at alternatives.

Comments

das-peter’s picture

What about using this:

$entity_id = $result->{$view->base_field};
jbova’s picture

Great job on this project. In my case, the node published date was the first column in my view, meaning the substitutions did not work.

The solution proposed by das-peter was applied and tested successfully.

bojanz’s picture

Status: Active » Fixed

We should just use $view->query->get_result_entities();
It's nice and consistent, and will allow us to use Search API views as well, as soon as they fix #1308928: SearchApiViewsQuery should implement get_result_entities().

Committed: http://drupalcode.org/project/entityreference_view_widget.git/commitdiff...

fangel’s picture

Also, in the latest Views 7.x-dev (as of today, Oct. 14) get_result_entities is returning the entities keyed by row-id, not entity-id (as indicated by this comment "Re-key the array by row-index.". So entity_extract_ids should really be used instead to find the entity-id.

I changed entityreference_view_widget_field_widget_form to use the following instead

  list($entity_type, $result_entities) = $view->query->get_result_entities($view->result);
  foreach ($result_entities as $row_id => $entity) {
    list($entity_id, , $bundle) = entity_extract_ids($entity_type, $entity);
    // ....
  }
bojanz’s picture

I suck :/ Committed a followup.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.