You are here

protected function EntityMatcher::buildEntityQuery in Linkit 8.5

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

Builds an EntityQuery to get entities.

Parameters

string $search_string: 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.

5 calls to EntityMatcher::buildEntityQuery()
ContactFormMatcher::buildEntityQuery in src/Plugin/Linkit/Matcher/ContactFormMatcher.php
Builds an EntityQuery to get entities.
EntityMatcher::execute in src/Plugin/Linkit/Matcher/EntityMatcher.php
Executes the matcher.
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.
4 methods override EntityMatcher::buildEntityQuery()
ContactFormMatcher::buildEntityQuery in src/Plugin/Linkit/Matcher/ContactFormMatcher.php
Builds an EntityQuery to get entities.
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 363

Class

EntityMatcher
Provides default linkit matchers for all entity types.

Namespace

Drupal\linkit\Plugin\Linkit\Matcher

Code

protected function buildEntityQuery($search_string) {
  $search_string = $this->database
    ->escapeLike($search_string);
  $entity_type = $this->entityTypeManager
    ->getDefinition($this->targetType);
  $query = $this->entityTypeManager
    ->getStorage($this->targetType)
    ->getQuery();
  $label_key = $entity_type
    ->getKey('label');
  if ($label_key) {

    // For configuration entities, the condition needs to be CONTAINS as
    // the matcher does not support LIKE.
    if ($entity_type instanceof ConfigEntityTypeInterface) {
      $query
        ->condition($label_key, $search_string, 'CONTAINS');
    }
    else {
      $query
        ->condition($label_key, '%' . $search_string . '%', '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');
  }
  if ($this->configuration['limit']) {
    $query
      ->range(0, $this->configuration['limit']);
  }
  $this
    ->addQueryTags($query);
  return $query;
}