public static function SearchApiQuery::getEntityFromRow in Search API 8
Retrieves the contained entity from a Views result row.
Parameters
\Drupal\search_api\Plugin\views\ResultRow $row: The Views result row.
string $relationship_id: The ID of the view relationship to use.
\Drupal\views\ViewExecutable $view: The current view object.
Return value
\Drupal\Core\Entity\EntityInterface|null The entity contained in the result row, if any.
File
- src/
Plugin/ views/ query/ SearchApiQuery.php, line 180
Class
- SearchApiQuery
- Defines a Views query class for searching on Search API indexes.
Namespace
Drupal\search_api\Plugin\views\queryCode
public static function getEntityFromRow(ResultRow $row, $relationship_id, ViewExecutable $view) {
if ($relationship_id === 'none') {
try {
$object = $row->_object ?: $row->_item
->getOriginalObject();
} catch (SearchApiException $e) {
return NULL;
}
$entity = $object
->getValue();
if ($entity instanceof EntityInterface) {
return $entity;
}
return NULL;
}
// To avoid code duplication, just create a dummy field handler and use it
// to retrieve the entity.
$handler = new SearchApiStandard([], '', [
'title' => '',
]);
$options = [
'relationship' => $relationship_id,
];
$handler
->init($view, $view->display_handler, $options);
return $handler
->getEntity($row);
}