You are here

protected function UserMatcher::buildEntityQuery in Linkit 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/Linkit/Matcher/UserMatcher.php \Drupal\linkit\Plugin\Linkit\Matcher\UserMatcher::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.

Overrides EntityMatcher::buildEntityQuery

File

src/Plugin/Linkit/Matcher/UserMatcher.php, line 98
Contains \Drupal\linkit\Plugin\Linkit\Matcher\UserMatcher.

Class

UserMatcher
Plugin annotation @Matcher( id = "entity:user", target_entity = "user", label = @Translation("User"), provider = "user" )

Namespace

Drupal\linkit\Plugin\Linkit\Matcher

Code

protected function buildEntityQuery($match) {
  $query = parent::buildEntityQuery($match);
  $match = $this->database
    ->escapeLike($match);

  // The user entity don't specify a label key so we have to do it instead.
  $query
    ->condition('name', '%' . $match . '%', 'LIKE');

  // Filter by role.
  if (!empty($this->configuration['roles'])) {
    $query
      ->condition('roles', $this->configuration['roles'], 'IN');
  }
  if ($this->configuration['include_blocked'] !== TRUE || !$this->currentUser
    ->hasPermission('administer users')) {
    $query
      ->condition('status', 1);
  }
  return $query;
}