You are here

public function ViewsUIController::autocompleteTag in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views_ui/src/Controller/ViewsUIController.php \Drupal\views_ui\Controller\ViewsUIController::autocompleteTag()

Menu callback for Views tag autocompletion.

Like other autocomplete functions, this function inspects the 'q' query parameter for the string to use to search for suggestions.

Return value

\Symfony\Component\HttpFoundation\JsonResponse A JSON response containing the autocomplete suggestions for Views tags.

1 string reference to 'ViewsUIController::autocompleteTag'
views_ui.routing.yml in core/modules/views_ui/views_ui.routing.yml
core/modules/views_ui/views_ui.routing.yml

File

core/modules/views_ui/src/Controller/ViewsUIController.php, line 187
Contains \Drupal\views_ui\Controller\ViewsUIController.

Class

ViewsUIController
Returns responses for Views UI routes.

Namespace

Drupal\views_ui\Controller

Code

public function autocompleteTag(Request $request) {
  $matches = array();
  $string = $request->query
    ->get('q');

  // Get matches from default views.
  $views = $this
    ->entityManager()
    ->getStorage('view')
    ->loadMultiple();
  foreach ($views as $view) {
    $tag = $view
      ->get('tag');
    if ($tag && strpos($tag, $string) === 0) {
      $matches[$tag] = $tag;
      if (count($matches) >= 10) {
        break;
      }
    }
  }
  return new JsonResponse($matches);
}