protected function SearchApiEntity::getItem in Search API 8
Creates an item for the given entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity.
Return value
array|null NULL if the entity should not be displayed. Otherwise, an associative array with at least "value" set, to either a string or a render array, and possibly also additional alter options.
Throws
\Drupal\Core\Entity\EntityMalformedException Thrown if the entity is malformed and a URL needs to be generated.
1 call to SearchApiEntity::getItem()
- SearchApiEntity::getItems in src/
Plugin/ views/ field/ SearchApiEntity.php - Gets an array of items for the field.
File
- src/
Plugin/ views/ field/ SearchApiEntity.php, line 298
Class
- SearchApiEntity
- Handles the display of entity reference fields in Search API Views.
Namespace
Drupal\search_api\Plugin\views\fieldCode
protected function getItem(EntityInterface $entity) {
$bundle = $entity
->bundle();
$display_method = $this
->getDisplayMethod($bundle);
if (!$display_method) {
return NULL;
}
if (in_array($display_method, [
'id',
'label',
])) {
if ($display_method == 'label') {
$item['value'] = $entity
->label();
}
else {
$item['value'] = $entity
->id();
}
if ($this->options['link_to_item']) {
$item['make_link'] = TRUE;
$item['url'] = $entity
->toUrl('canonical');
}
return $item;
}
$view_mode = $this->options['display_methods'][$bundle]['view_mode'];
$build = $this
->getEntityTypeManager()
->getViewBuilder($entity
->getEntityTypeId())
->view($entity, $view_mode);
return [
'value' => $build,
];
}