8 autocomplete pass current value to function I am trying to use autocomplete in a custom form, but I don't know how to pass the current value of the field to the autocomplete function.

This is my form element:

  $form['gs_name'] = [
    '#type' =&gt; 'textfield',
    '#title' =&gt; $this-&gt;t("Name"),
    '#autocomplete_route_name' =&gt; 'gseight_autocomplete',
    //'#autocomplete_parameters' =&gt; array(),
    '#required' =&gt; TRUE,
  ];


Route:

gseight_autocomplete:
  path: 'gseight_autocomplete'
  defaults:
    _controller: '\Drupal\gseight\Controller\GsEightAutoComplete::content'
    _title: 'Autocomplete Results'
  requirements:
    _permission: 'access GS simple page'


Inside GsEightAutoComplete

public function content($q = '') {

    //get user
    $userCurrent = \Drupal::currentUser();
    $uid = $userCurrent-&gt;id();

    $selectthree = db_select('gs_plans','g');
    $selectthree-&gt;addField('g','gs_name');
    // Filter only current user".
    $selectthree-&gt;condition('g.uid', $uid);
    $selectthree-&gt;condition('g.gs_name', '%' . db_like($q) . '%', 'LIKE');

    $currentone = $selectthree-&gt;execute()-&gt;fetchAll();

    $jsonarray = array();

    foreach($currentone as $eachcurrentone) {
        $jsonarray[] = $eachcurrentone-&gt;gs_name;
    }

    return new JsonResponse($jsonarray);

    }


The array fills with items from the database that belong to the current user when i have $q = ''at the start. But how do I pass the current value of the field to q?
The form value is automagically added as a query parameter so it is not necessary to pass the current value. This is accessible in the Request object. The controller class method should be:

public function autocomplete(\Symfony\Component\HttpFoundation\Request $request) {
  $value = $request-&gt;query-&gt;get('q');
}