You are here

class MpacAutocompleteController in Multi-path autocomplete 8

Controller routines for mpax autocomplete routes.

Hierarchy

Expanded class hierarchy of MpacAutocompleteController

File

lib/Drupal/mpac/MpacAutocompleteController.php, line 17
Contains \Drupal\mpac\MpacAutocompleteController.

Namespace

Drupal\mpac
View source
class MpacAutocompleteController implements ContainerInjectionInterface {

  /**
   * The mpac autocomplete helper class to find matching items.
   *
   * @var \Drupal\mpac\MpacAutocomplete
   */
  protected $mpacAutocomplete;

  /**
   * Constructs an MpacAutocompleteController object.
   *
   * @param \Drupal\mpac\MpacAutocomplete $mpac_autocomplete
   *   The mpac autocomplete helper class to find matching items.
   */
  public function __construct(MpacAutocomplete $mpac_autocomplete) {
    $this->mpacAutocomplete = $mpac_autocomplete;
  }

  /**
   * Implements \Drupal\Core\ControllerInterface::create().
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('mpac.autocomplete'));
  }

  /**
   * Returns response for the mpac autocompletion.
   *
   * @param Request $request
   *   The current request object containing the search string.
   * @param string $type
   *   The type of data to find (i.e. "path" or "shortcut").
   *
   * @return JsonResponse
   *   A JSON response containing the autocomplete suggestions for existing users.
   *
   * @see MpacAutocomplete::getMatches()
   */
  public function autocompleteItems(Request $request, $type) {
    $matches = $this->mpacAutocomplete
      ->getMatches($type, $request->query
      ->get('q'));
    return new JsonResponse($matches);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MpacAutocompleteController::$mpacAutocomplete protected property The mpac autocomplete helper class to find matching items.
MpacAutocompleteController::autocompleteItems public function Returns response for the mpac autocompletion.
MpacAutocompleteController::create public static function Implements \Drupal\Core\ControllerInterface::create(). Overrides ContainerInjectionInterface::create
MpacAutocompleteController::__construct public function Constructs an MpacAutocompleteController object.