How to add highlighting to exposed views_autocomplete_filter in Drupal 8 Is there a way (a hook perhaps) that would allow me to modify the autocomplete fields returned by an exposed views_autocomplete_filter field?  I'd like to style the text typed into the field differently from the rest of the suggestion text.

Something like this:

------------------
| term_ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|
------------------------------
| terminal emulators      | 
------------------------------
| determination &nbsp; &nbsp; &nbsp; &nbsp; |
------------------------------
| midterm exams &nbsp; &nbsp; &nbsp;|
------------------------------
So it seems it is necessary to extend the ViewsAutocompleteFiltersController class to do this.  In order to override the routing so that a custom controller can be used instead, an entry must be added to /mymodule/mymodule.services.yml:

services:
  mymodule.route_subscriber:
    class: Drupal\mymodule\Routing\RouteSubscriber
    tags:
      - { name: event_subscriber }


Then provide your /mymodule/src/Routing/RouteSubscriber.php file, which redirects to our local ViewsAutocompleteFiltersController

&lt;?php

namespace Drupal\mymodule\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  public function alterRoutes(RouteCollection $collection) {
    // Replace "some.route.name" below with the actual route you want to override.
    if ($route = $collection-&gt;get('viewsfilters.autocomplete')) {
      $route-&gt;setDefaults(array(
        '_controller' =&gt; '\Drupal\mymodule\Controller\ViewsAutocompleteFiltersController::autocomplete',
      ));
    }
  }
}


Finally provide your local /mymodule/src/Controller/ViewsAutocompleteFiltersController.php which filters for the view of interest, then modifies the output of the base ViewsAutocompleteFiltersController.  The tricky part of that process is that the data member of the JsonResponse output is protected, so we use a customized JsonResponse wrapper to perform the highlighting:

&lt;?php

namespace Drupal\mymodule\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
 * Overrides default ViewsAutocompleteFiltersController to provide highlighting of autocomplete suggestions
 */
class ViewsAutocompleteFiltersController extends \Drupal\views_autocomplete_filters\Controller\ViewsAutocompleteFiltersController {

  /**
   * {@inheritdoc]
   */
  public function autocomplete(Request $request, $view_name, $view_display, $filter_name, $view_args) {

    $response = parent::autocomplete($request, $view_name, $view_display, $filter_name, $view_args);
    if($response instanceof JsonResponse &amp;&amp; $view_name === 'my_view' &amp;&amp; $view_display === 'my_view_display') {
      $response = new HighlightedJsonResponse($response, $request-&gt;query-&gt;get('q'));
    }
    return $response;
  }

}


/**
 * Overrides default JsonResponse to provide highlighting of autocomplete suggestions
 */
class HighlightedJsonResponse extends JsonResponse {

  function __construct($jsonResponse, $q) {

    $data = \json_decode($jsonResponse-&gt;data);
    if(isset($q)) {
      $qPattern = '/(' . preg_quote($q, '/') . ')/i';
      foreach($data as &amp;$datum) {
        if(isset($datum-&gt;label)) {
          $datum-&gt;label = '&lt;b&gt;' . \preg_replace($qPattern, '&lt;/b&gt;$0&lt;b&gt;', $datum-&gt;label) . '&lt;/b&gt;';
          $datum-&gt;label = \str_replace("&lt;b&gt;&lt;/b&gt;","",$datum-&gt;label);
        }
      }
    }

    parent::__construct($data, $jsonResponse-&gt;statusCode, $jsonResponse-&gt;headers-&gt;all());

  }
}