public function SearchApiRow::preRender in Search API 8
Allow the style to do stuff before each row is rendered.
Parameters
$result: The full array of results from the query.
Overrides RowPluginBase::preRender
File
- src/
Plugin/ views/ row/ SearchApiRow.php, line 151
Class
- SearchApiRow
- Provides a row plugin for displaying a result as a rendered item.
Namespace
Drupal\search_api\Plugin\views\rowCode
public function preRender($result) {
// Load all result objects at once, before rendering.
// Set $entity->view property to be accessible in preprocess functions.
$items_to_load = [];
foreach ($result as $i => $row) {
if (empty($row->_object)) {
$items_to_load[$i] = $row->search_api_id;
}
else {
$entity = $row->_object
->getValue();
if ($entity instanceof EntityInterface && !isset($entity->view)) {
$entity->view = $this->view;
}
}
}
$items = $this->index
->loadItemsMultiple($items_to_load);
foreach ($items_to_load as $i => $item_id) {
if (isset($items[$item_id])) {
$result[$i]->_object = $items[$item_id];
$result[$i]->_item
->setOriginalObject($items[$item_id]);
$entity = $items[$item_id]
->getValue();
if ($entity instanceof EntityInterface && !isset($entity->view)) {
$entity->view = $this->view;
}
}
}
}