I recently ran into this rather cryptic error message:
Notice: Undefined property: stdClass::$_entity in Drupal\system\Plugin\views\row\EntityRow->pre_render() (line 123 of core/modules/system/lib/Drupal/system/Plugin/views/row/EntityRow.php).
In Drupal\system\Plugin\views\row\EntityRow:
public function pre_render($result) {
parent::pre_render($result);
if ($result) {
// Get all entities which will be used to render in rows.
$entities = array();
foreach ($result as $row) {
$entity = $row->_entity;
$entity->view = $this->view;
$entities[$entity->id()] = $entity;
}
// Prepare the render arrays for all rows.
$this->build = entity_view_multiple($entities, $this->options['view_mode']);
}
}
The initial value of $row->_entity is FALSE I believe, and if that's not populated with an entity by the time this code runs, the initial value of $entity is FALSE. What's crazy, is even if $entity is FALSE, $entity->view = $this->view
will turn $entity into a stdClass.
Perhaps this is a symptom of a larger issue, but I'd think views could use more validation around this since this error message is always going to be confusing.
Comments
Comment #1
tim.plunkettTagging
Comment #10
LendudeCleaning up old bugs.
Wow, some of this code still exists. The most common way to run into $row->_entity not being set is #2457999: Cannot use relationship for rendered entity on Views and since this doesn't have specific steps to reproduce it in this case, I'm going to close this as a duplicate of that.
If this had another origin, then please feel free to reopen this.