public function ViewsSelection::getReferencableEntities

Implements \Drupal\entity_reference\Plugin\Type\Selection\SelectionInterface::getReferencableEntities().

Overrides SelectionInterface::getReferencableEntities

1 call to ViewsSelection::getReferencableEntities()

File

drupal/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php, line 145
Contains \Drupal\views\Plugin\entity_reference\selection\ViewsSelection.

Class

ViewsSelection
Plugin implementation of the 'selection' entity_reference.

Namespace

Drupal\views\Plugin\entity_reference\selection

Code

public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
  $display_name = $this->instance['settings']['handler_settings']['view']['display_name'];
  $arguments = $this->instance['settings']['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;
}