public function EntityMatcher::getMatches in Linkit 8.4
Gets an array with search matches that will be presented in the autocomplete widget.
Parameters
$string: The string that contains the text to search for.
Return value
array An array whose values are an associative array containing:
- title: A string to use as the search result label.
- description: (optional) A string with additional information about the result item.
- path: The URL to the item.
- group: (optional) A string with the group name for the result item. Best practice is to use the plugin name as group name.
Overrides MatcherInterface::getMatches
File
- src/
Plugin/ Linkit/ Matcher/ EntityMatcher.php, line 217 - 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\MatcherCode
public function getMatches($string) {
$query = $this
->buildEntityQuery($string);
$result = $query
->execute();
if (empty($result)) {
return [];
}
$matches = [];
$entities = $this->entityManager
->getStorage($this->target_type)
->loadMultiple($result);
foreach ($entities as $entity_id => $entity) {
// Check the access against the defined entity access handler.
/** @var \Drupal\Core\Access\AccessResultInterface $access */
$access = $entity
->access('view', $this->currentUser, TRUE);
if (!$access
->isAllowed()) {
continue;
}
$matches[] = [
'title' => $this
->buildLabel($entity),
'description' => $this
->buildDescription($entity),
'path' => $this
->buildPath($entity),
'group' => $this
->buildGroup($entity),
];
}
return $matches;
}