You are here

public function ViewsSelection::getReferenceableEntities in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php \Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::getReferenceableEntities()

Gets the list of referenceable entities.

Return value

array A nested array of entities, the first level is keyed by the entity bundle, which contains an array of entity labels (escaped), keyed by the entity ID.

Overrides SelectionInterface::getReferenceableEntities

1 call to ViewsSelection::getReferenceableEntities()
ViewsSelection::countReferenceableEntities in core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
Counts entities that are referenceable.

File

core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php, line 218
Contains \Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection.

Class

ViewsSelection
Plugin implementation of the 'selection' entity_reference.

Namespace

Drupal\views\Plugin\EntityReferenceSelection

Code

public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
  $handler_settings = $this->configuration['handler_settings'];
  $display_name = $handler_settings['view']['display_name'];
  $arguments = $handler_settings['view']['arguments'];
  $result = array();
  if ($this
    ->initializeView($match, $match_operator, $limit)) {

    // Get the results.
    $result = $this->view
      ->executeDisplay($display_name, $arguments);
  }
  $return = array();
  if ($result) {
    foreach ($this->view->result as $row) {
      $entity = $row->_entity;
      $return[$entity
        ->bundle()][$entity
        ->id()] = $entity
        ->label();
    }
  }
  return $return;
}