You are here

protected function EntityReference_SelectionHandler_Views::initializeView in Entity reference 7

2 calls to EntityReference_SelectionHandler_Views::initializeView()
EntityReference_SelectionHandler_Views::getReferencableEntities in plugins/selection/EntityReference_SelectionHandler_Views.class.php
Implements EntityReferenceHandler::getReferencableEntities().
EntityReference_SelectionHandler_Views::validateReferencableEntities in plugins/selection/EntityReference_SelectionHandler_Views.class.php
Validate that entities can be referenced by this field.

File

plugins/selection/EntityReference_SelectionHandler_Views.class.php, line 94

Class

EntityReference_SelectionHandler_Views
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;
}