You are here

private function NodeSelection::buildEntityQuery in Multi-path autocomplete 8

Builds an EntityQuery to get matching nodes.

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".

Return value

\Drupal\Core\Entity\Query\QueryInterface The EntityQuery object with the basic conditions applied to it.

2 calls to NodeSelection::buildEntityQuery()
NodeSelection::countMatchingItems in lib/Drupal/mpac/Plugin/mpac/selection/NodeSelection.php
Counts items that matches against the given string.
NodeSelection::getMatchingItems in lib/Drupal/mpac/Plugin/mpac/selection/NodeSelection.php
Returns a list of matching items.

File

lib/Drupal/mpac/Plugin/mpac/selection/NodeSelection.php, line 73
Contains \Drupal\mpac\Plugin\mpac\selection\NodeSelection.

Class

NodeSelection
Provides specific selection functions for nodes.

Namespace

Drupal\mpac\Plugin\mpac\selection

Code

private function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
  $target_type = 'node';
  $entity_info = entity_get_info($target_type);
  $query = \Drupal::entityQuery($target_type);
  if (isset($match) && isset($entity_info['entity_keys']['label'])) {
    $query
      ->condition($entity_info['entity_keys']['label'], $match, $match_operator);
  }

  // Add entity-access tag.
  $query
    ->addTag('node_access');

  // Adding the 'node_access' tag is sadly insufficient for nodes: core
  // requires us to also know about the concept of 'published' and
  // 'unpublished'. We need to do that as long as there are no access control
  // modules in use on the site. As long as one access control module is there,
  // it is supposed to handle this check.
  if (!user_access('bypass node access') && !count(module_implements('node_grants'))) {
    $query
      ->condition('status', NODE_PUBLISHED);
  }
  return $query;
}