protected function ViewsSelection::initializeView

Initializes a view.

Parameters

string|null $match: (Optional) Text to match the label against. Defaults to NULL.

string $match_operator: (Optional) The operation the matching should be done with. Defaults to "CONTAINS".

int $limit: Limit the query to a given number of items. Defaults to 0, which indicates no limiting.

array|null $ids: Array of entity IDs. Defaults to NULL.

Return value

bool Return TRUE if the view was initialized, FALSE otherwise.

2 calls to ViewsSelection::initializeView()

File

drupal/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php, line 119
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

protected function initializeView($match = NULL, $match_operator = 'CONTAINS', $limit = 0, $ids = NULL) {
  $view_name = $this->instance['settings']['handler_settings']['view']['view_name'];
  $display_name = $this->instance['settings']['handler_settings']['view']['display_name'];

  // Check that the view is valid and the display still exists.
  $this->view = views_get_view($view_name);
  if (!$this->view || !$this->view
    ->access($display_name)) {
    drupal_set_message(t('The reference view %view_name used in the %field_name field cannot be found.', array(
      '%view_name' => $view_name,
      '%field_name' => $this->instance['label'],
    )), 'warning');
    return FALSE;
  }
  $this->view
    ->setDisplay($display_name);

  // Pass options to the display handler to make them available later.
  $entity_reference_options = array(
    'match' => $match,
    'match_operator' => $match_operator,
    'limit' => $limit,
    'ids' => $ids,
  );
  $this->view->displayHandlers
    ->get($display_name)
    ->setOption('entity_reference_options', $entity_reference_options);
  return TRUE;
}