Unverified Commit 22679266 authored by alexpott's avatar alexpott
Browse files

Issue #3101516 by blazey: Add the EntityAutocompleteMatcherInterface

parent f8c0cf38
......@@ -9,7 +9,7 @@
/**
* Matcher class to get autocompletion results for entity reference.
*/
class EntityAutocompleteMatcher {
class EntityAutocompleteMatcher implements EntityAutocompleteMatcherInterface {
/**
* The entity reference selection handler plugin manager.
......@@ -29,25 +29,7 @@ public function __construct(SelectionPluginManagerInterface $selection_manager)
}
/**
* Gets matched labels based on a given search string.
*
* @param string $target_type
* The ID of the target entity type.
* @param string $selection_handler
* The plugin ID of the entity reference selection handler.
* @param array $selection_settings
* An array of settings that will be passed to the selection handler.
* @param string $string
* (optional) The label of the entity to query by.
*
* @return array
* An array of matched entity labels, in the format required by the AJAX
* autocomplete API (e.g. array('value' => $value, 'label' => $label)).
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* Thrown when the current user doesn't have access to the specified entity.
*
* @see \Drupal\system\Controller\EntityAutocompleteController
* {@inheritDoc}
*/
public function getMatches($target_type, $selection_handler, $selection_settings, $string = '') {
$matches = [];
......
<?php
namespace Drupal\Core\Entity;
interface EntityAutocompleteMatcherInterface {
/**
* Gets matched labels based on a given search string.
*
* @param string $target_type
* The ID of the target entity type.
* @param string $selection_handler
* The plugin ID of the entity reference selection handler.
* @param array $selection_settings
* An array of settings that will be passed to the selection handler.
* @param string $string
* (optional) The label of the entity to query by.
*
* @return array
* An array of matched entity labels, in the format required by the AJAX
* autocomplete API (e.g. array('value' => $value, 'label' => $label)).
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* Thrown when the current user doesn't have access to the specified entity.
*
* @see \Drupal\system\Controller\EntityAutocompleteController
*/
public function getMatches($target_type, $selection_handler, $selection_settings, $string = '');
}
......@@ -5,7 +5,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityAutocompleteMatcher;
use Drupal\Core\Entity\EntityAutocompleteMatcherInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\Core\Site\Settings;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -21,7 +21,7 @@ class EntityAutocompleteController extends ControllerBase {
/**
* The autocomplete matcher for entity references.
*
* @var \Drupal\Core\Entity\EntityAutocompleteMatcher
* @var \Drupal\Core\Entity\EntityAutocompleteMatcherInterface
*/
protected $matcher;
......@@ -35,12 +35,12 @@ class EntityAutocompleteController extends ControllerBase {
/**
* Constructs a EntityAutocompleteController object.
*
* @param \Drupal\Core\Entity\EntityAutocompleteMatcher $matcher
* @param \Drupal\Core\Entity\EntityAutocompleteMatcherInterface $matcher
* The autocomplete matcher for entity references.
* @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value
* The key value factory.
*/
public function __construct(EntityAutocompleteMatcher $matcher, KeyValueStoreInterface $key_value) {
public function __construct(EntityAutocompleteMatcherInterface $matcher, KeyValueStoreInterface $key_value) {
$this->matcher = $matcher;
$this->keyValue = $key_value;
}
......
......@@ -77,7 +77,7 @@ public function testUserSelectionByRole() {
$user3->addRole($this->role2->id());
$user3->save();
/** @var \Drupal\Core\Entity\EntityAutocompleteMatcher $autocomplete */
/** @var \Drupal\Core\Entity\EntityAutocompleteMatcherInterface $autocomplete */
$autocomplete = \Drupal::service('entity.autocomplete_matcher');
$matches = $autocomplete->getMatches('user', 'default', $field_definition->getSetting('handler_settings'), 'aabb');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment