Download & Extend

#autocomplete_path now passes the search string as a GET argument instead of appending to the URL

Project: 
Drupal core
Introduced in branch: 
8.x
Description: 

The #autocomplete_path form API property has been changed to to pass the search query string as the GET argument q because the new router system breaks the ability to have '/' in a search string.

The two affected autocomplete implementations in core are user/autocomplete and taxonomy/autocomplete/field_name. The request for the user autocomplete with the search string "Ad" is changed from user/autocomplete/Ad to user/autocomplete?q=Ad.

Page callbacks/controllers need to be updated to read the search string from the request object.
7.x

<?php
function mymodule_autocomplete($string = '') {
 
// If the request has a '/' in the search text, then the menu system will have
  // split it into multiple arguments, recover the intended $string.
 
$args = func_get_args();
 
$string = implode('/', $args);
 
// ...
}
?>

8.x

<?php
function mymodule_autocomplete() {
 
$string = Drupal::service('request')->query->get('q');
 
// ...
}
?>
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done
nobody click here