Updated: Comment #0
Follow-up from #1987858: Convert taxonomy_autocomplete() to a new style controller and #2056627-22: Form API autocomplete is broken for routes where @tim.plunkett said

If we convert the taxonomy autocomplete before this goes in, then it too will be broken...
If that is the last usage of #autocomplete_path, why not put this in now, and then remove #autocomplete_path over there.

Problem/Motivation

In #2056627: Form API autocomplete is broken for routes we have added route based autocomplete #autocomplete_route. Developers should use #autocomplete_route going forward instead of #autocomplete_path.

Proposed resolution

Remove #autocomplete_path from form_process_autocomplete in form.inc.

Remaining tasks

More discussion and patch.

User interface changes

None.

API changes

New api is added in #2056627: Form API autocomplete is broken for routes we are removing old api.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jibran’s picture

Status: Active » Needs review
Issue tags: +API clean-up
FileSize
6.25 KB

Let's see how much it fails.

dawehner’s picture

  1. +++ b/core/includes/form.inc
    @@ -4071,17 +4071,13 @@ function theme_vertical_tabs($variables) {
    + * Adds autocomplete functionality to elements with a valid
    + * #autocomplete_route_name.
    

    Mh, actually the one-line description of a function should be one-line.

  2. +++ b/core/modules/system/system.module
    @@ -325,7 +325,7 @@ function system_element_info() {
         '#size' => 60,
         '#maxlength' => 128,
    -    '#autocomplete_path' => FALSE,
    +    '#autocomplete_route_name' => FALSE,
         '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'),
         '#pre_render' => array('form_pre_render_textfield'),
    

    What about also setting #autocomplete_route_parameters to FALSE or an empty array.

jibran’s picture

Thank you for the review @dawehner fixed #2.

Status: Needs review » Needs work

The last submitted patch, drupal8.forms-system.2071115-3.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
2.99 KB
6.54 KB

Test Fixes

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Ha, this makes totally sense.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Can we not default #autocomplete_route_parameters to an array if #autocomplete_route is set?

amateescu’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
3.24 KB
6.31 KB

We do that already, those assignments in system_element_info() were totally not needed.

Here's the relevant part from form_process_autocomplete():

function form_process_autocomplete($element, &$form_state) {
  $access = FALSE;
  if (!empty($element['#autocomplete_route_name'])) {
    $parameters = isset($element['#autocomplete_route_parameters']) ? $element['#autocomplete_route_parameters'] : array();

    $path = \Drupal::urlGenerator()->generate($element['#autocomplete_route_name'], $parameters);
    $access = \Drupal::service('access_manager')->checkNamedRoute($element['#autocomplete_route_name'], $parameters);
  }
...

Fixed that and the doxygen of form_process_autocomplete() which was missing the example path.

dawehner’s picture

Perfect!

catch’s picture

Title: Remove #autocomplete_path in favor of #autocomplete_route » Change notice: Remove #autocomplete_path in favor of #autocomplete_route
Priority: Normal » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Committed/pushed to 8.x, thanks!

Will need a change notice.

dawehner’s picture

Status: Active » Fixed
jibran’s picture

Title: Change notice: Remove #autocomplete_path in favor of #autocomplete_route » Remove #autocomplete_path in favor of #autocomplete_route
Priority: Major » Normal
Issue tags: -Needs change record +Approved API change

Fixed the change notice title and added issue to change notice. Thank you everybody for the help.

Automatically closed -- issue fixed for 2 weeks with no activity.