You are here

protected function ElasticsearchViewsEntity::getItem in Elasticsearch Connector 8.2

Same name and namespace in other branches
  1. 8.7 modules/elasticsearch_connector_views/src/Plugin/views/field/ElasticsearchViewsEntity.php \Drupal\elasticsearch_connector_views\Plugin\views\field\ElasticsearchViewsEntity::getItem()
  2. 8.5 modules/elasticsearch_connector_views/src/Plugin/views/field/ElasticsearchViewsEntity.php \Drupal\elasticsearch_connector_views\Plugin\views\field\ElasticsearchViewsEntity::getItem()
  3. 8.6 modules/elasticsearch_connector_views/src/Plugin/views/field/ElasticsearchViewsEntity.php \Drupal\elasticsearch_connector_views\Plugin\views\field\ElasticsearchViewsEntity::getItem()

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.

1 call to ElasticsearchViewsEntity::getItem()
ElasticsearchViewsEntity::getItems in modules/elasticsearch_connector_views/src/Plugin/views/field/ElasticsearchViewsEntity.php

File

modules/elasticsearch_connector_views/src/Plugin/views/field/ElasticsearchViewsEntity.php, line 251

Class

ElasticsearchViewsEntity
Handles the display of entity reference fields in Search API Views.

Namespace

Drupal\elasticsearch_connector_views\Plugin\views\field

Code

protected function getItem(EntityInterface $entity) {
  $bundle = $entity
    ->bundle();
  if (empty($this->options['display_methods'][$bundle]['display_method'])) {
    return NULL;
  }
  $display_method = $this->options['display_methods'][$bundle]['display_method'];
  if (in_array($display_method, array(
    '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
    ->getEntityManager()
    ->getViewBuilder($entity
    ->getEntityTypeId())
    ->view($entity, $view_mode);
  return array(
    'value' => $build,
  );
}