CategoryAutocompleteController::autocomplete

public CategoryAutocompleteController::autocomplete(Request $request)

Retrieves suggestions for block category autocompletion.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

\Symfony\Component\HttpFoundation\JsonResponse A JSON response containing autocomplete suggestions.

File

core/modules/block/src/Controller/CategoryAutocompleteController.php, line 52

Class

CategoryAutocompleteController
Returns autocomplete responses for block categories.

Namespace

Drupal\block\Controller

Code

public function autocomplete(Request $request) {
  $typed_category = $request->query->get('q');
  $matches = array();
  foreach ($this->blockManager->getCategories() as $category) {
    if (stripos($category, $typed_category) === 0) {
      $matches[] = array('value' => $category, 'label' => Html::escape($category));
    }
  }
  return new JsonResponse($matches);
}
doc_Drupal
2016-10-29 08:49:39
Comments
Leave a Comment

Please login to continue.