You are here

protected function BusinessRulesViewsSelection::initializeView in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php \Drupal\business_rules\Plugin\EntityReferenceSelection\BusinessRulesViewsSelection::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.

3 calls to BusinessRulesViewsSelection::initializeView()
BusinessRulesViewsSelection::getReferenceableEntities in src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php
Gets the list of referenceable entities.
BusinessRulesViewsSelection::getValidIds in src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php
Return valid ids for validation.
BusinessRulesViewsSelection::validateReferenceableEntities in src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php
Validates which existing entities can be referenced.

File

src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php, line 391

Class

BusinessRulesViewsSelection
Plugin override of the 'selection' entity_reference.

Namespace

Drupal\business_rules\Plugin\EntityReferenceSelection

Code

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

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

  // Pass options to the display handler to make them available later.
  $entity_reference_options = [
    '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;
}