1 EntityReferenceSelectionHandlerViews.inc protected EntityReferenceSelectionHandlerViews::initializeView($match = NULL, $match_operator = 'CONTAINS', $limit = 0, $ids = NULL)

File

core/modules/entityreference/plugins/selection/EntityReferenceSelectionHandlerViews.inc, line 96

Class

EntityReferenceSelectionHandlerViews
Entity handler for Views.

Code

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

  // Check that the view is valid and the display still exists.
  $this->view = views_get_view($view_name);
  if (!$this->view || !isset($this->view->display[$display_name]) || !$this->view->access($display_name)) {
    watchdog('entityreference', 'The view %view_name is no longer eligible for the %field_name field.', array('%view_name' => $view_name, '%field_name' => $this->instance['label']), WATCHDOG_WARNING);
    return FALSE;
  }
  $this->view->set_display($display_name);
  $this->view->pre_execute();

  // Make sure the query is not cached.
  $this->view->is_cacheable = FALSE;

  // Pass options to the display handler to make them available later.
  $entityreference_options = array(
    'match' => $match,
    'match_operator' => $match_operator,
    'limit' => $limit,
    'ids' => $ids,
  );
  $this->view->display_handler->set_option('entityreference_options', $entityreference_options);
  return TRUE;
}