You are here

protected function EntityMatcher::buildEntityQuery in Linkit 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/Linkit/Matcher/EntityMatcher.php \Drupal\linkit\Plugin\Linkit\Matcher\EntityMatcher::buildEntityQuery()

Builds an EntityQuery to get entities.

Parameters

$match: Text to match the label against.

Return value

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

4 calls to EntityMatcher::buildEntityQuery()
EntityMatcher::getMatches in src/Plugin/Linkit/Matcher/EntityMatcher.php
Gets an array with search matches that will be presented in the autocomplete widget.
FileMatcher::buildEntityQuery in src/Plugin/Linkit/Matcher/FileMatcher.php
Builds an EntityQuery to get entities.
NodeMatcher::buildEntityQuery in src/Plugin/Linkit/Matcher/NodeMatcher.php
Builds an EntityQuery to get entities.
UserMatcher::buildEntityQuery in src/Plugin/Linkit/Matcher/UserMatcher.php
Builds an EntityQuery to get entities.
3 methods override EntityMatcher::buildEntityQuery()
FileMatcher::buildEntityQuery in src/Plugin/Linkit/Matcher/FileMatcher.php
Builds an EntityQuery to get entities.
NodeMatcher::buildEntityQuery in src/Plugin/Linkit/Matcher/NodeMatcher.php
Builds an EntityQuery to get entities.
UserMatcher::buildEntityQuery in src/Plugin/Linkit/Matcher/UserMatcher.php
Builds an EntityQuery to get entities.

File

src/Plugin/Linkit/Matcher/EntityMatcher.php, line 257
Contains \Drupal\linkit\Plugin\Linkit\Matcher\EntityMatcher.

Class

EntityMatcher
Plugin annotation @Matcher( id = "entity", label = @Translation("Entity"), deriver = "\Drupal\linkit\Plugin\Derivative\EntityMatcherDeriver" )

Namespace

Drupal\linkit\Plugin\Linkit\Matcher

Code

protected function buildEntityQuery($match) {
  $match = $this->database
    ->escapeLike($match);
  $entity_type = $this->entityManager
    ->getDefinition($this->target_type);
  $query = $this->entityManager
    ->getStorage($this->target_type)
    ->getQuery();
  $label_key = $entity_type
    ->getKey('label');
  if ($label_key) {
    $query
      ->condition($label_key, '%' . $match . '%', 'LIKE');
    $query
      ->sort($label_key, 'ASC');
  }

  // Bundle check.
  if (!empty($this->configuration['bundles']) && ($bundle_key = $entity_type
    ->getKey('bundle'))) {
    $query
      ->condition($bundle_key, $this->configuration['bundles'], 'IN');
  }

  // Add tags to let other modules alter the query.
  $query
    ->addTag('linkit_entity_autocomplete');
  $query
    ->addTag('linkit_entity_' . $this->target_type . '_autocomplete');

  // Add access tag for the query.
  $query
    ->addTag('entity_access');
  $query
    ->addTag($this->target_type . '_access');
  return $query;
}