Issue #2071115 by jibran, amateescu: Remove #autocomplete_path in favor of #autocomplete_route.

8.0.x
Nathaniel Catchpole 2013-10-15 12:54:21 +01:00
parent 4f732c0127
commit 2977e2ab57
4 changed files with 13 additions and 22 deletions

View File

@ -4073,17 +4073,14 @@ function theme_vertical_tabs($variables) {
}
/**
* Adds autocomplete functionality to elements with a valid #autocomplete_path.
* Adds autocomplete functionality to elements with a valid
* #autocomplete_route_name.
*
* Suppose your autocomplete path in the menu system is 'mymodule_autocomplete.'
* Suppose your autocomplete route name is 'mymodule.autocomplete' and its path
* is: '/mymodule/autocomplete/{a}/{b}'
* In your form you have:
* @code
* '#autocomplete_path' => 'mymodule_autocomplete/' . $some_key . '/' . $some_id,
* @endcode
* Or if your route is called 'mymodule_autocomplete' with the path of
* '/mymodule-autocomplete/{a}/{b}':
* @code
* '#autocomplete_route_name' => 'mymodule_autocomplete',
* '#autocomplete_route_name' => 'mymodule.autocomplete',
* '#autocomplete_route_parameters' => array('a' => $some_key, 'b' => $some_id),
* @endcode
* The user types in "keywords" so the full path called is:
@ -4091,8 +4088,6 @@ function theme_vertical_tabs($variables) {
*
* @param array $element
* The form element to process. Properties used:
* - #autocomplete_path: A system path to be used as callback URL by the
* autocomplete JavaScript library.
* - #autocomplete_route_name: A route to be used as callback URL by the
* autocomplete JavaScript library.
* - #autocomplete_route_parameters: The parameters to be used in conjunction
@ -4111,10 +4106,6 @@ function form_process_autocomplete($element, &$form_state) {
$path = \Drupal::urlGenerator()->generate($element['#autocomplete_route_name'], $parameters);
$access = \Drupal::service('access_manager')->checkNamedRoute($element['#autocomplete_route_name'], $parameters);
}
elseif (!empty($element['#autocomplete_path'])) {
$path = url($element['#autocomplete_path'], array('absolute' => TRUE));
$access = drupal_valid_path($element['#autocomplete_path']);
}
if ($access) {
$element['#attributes']['class'][] = 'form-autocomplete';
$element['#attached']['library'][] = array('system', 'drupal.autocomplete');

View File

@ -238,7 +238,7 @@ function hook_field_widget_WIDGET_TYPE_form_alter(&$element, &$form_state, $cont
// Code here will only act on widgets of type WIDGET_TYPE. For example,
// hook_field_widget_mymodule_autocomplete_form_alter() will only act on
// widgets of type 'mymodule_autocomplete'.
$element['#autocomplete_path'] = 'mymodule/autocomplete_path';
$element['#autocomplete_route_name'] = 'mymodule.autocomplete_route';
}
/**

View File

@ -325,7 +325,7 @@ function system_element_info() {
'#input' => TRUE,
'#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'),
'#theme' => 'input__textfield',
@ -335,7 +335,7 @@ function system_element_info() {
'#input' => TRUE,
'#size' => 30,
'#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_tel'),
'#theme' => 'input__tel',
@ -346,7 +346,7 @@ function system_element_info() {
'#size' => 60,
// user.module is not loaded in case of early bootstrap errors.
'#maxlength' => defined('EMAIL_MAX_LENGTH') ? EMAIL_MAX_LENGTH : 255,
'#autocomplete_path' => FALSE,
'#autocomplete_route_name' => FALSE,
'#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'),
'#element_validate' => array('form_validate_email'),
'#pre_render' => array('form_pre_render_email'),
@ -357,7 +357,7 @@ function system_element_info() {
'#input' => TRUE,
'#size' => 60,
'#maxlength' => 255,
'#autocomplete_path' => FALSE,
'#autocomplete_route_name' => FALSE,
'#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'),
'#element_validate' => array('form_validate_url'),
'#pre_render' => array('form_pre_render_url'),
@ -368,7 +368,7 @@ function system_element_info() {
'#input' => TRUE,
'#size' => 60,
'#maxlength' => 128,
'#autocomplete_path' => FALSE,
'#autocomplete_route_name' => FALSE,
'#process' => array('form_process_autocomplete', 'ajax_process_form'),
'#pre_render' => array('form_pre_render_search'),
'#theme' => 'input__search',
@ -408,7 +408,7 @@ function system_element_info() {
'#required' => TRUE,
'#maxlength' => 64,
'#size' => 60,
'#autocomplete_path' => FALSE,
'#autocomplete_route_name' => FALSE,
'#process' => array('form_process_machine_name', 'form_process_autocomplete', 'ajax_process_form'),
'#element_validate' => array('form_validate_machine_name'),
'#pre_render' => array('form_pre_render_textfield'),

View File

@ -59,7 +59,7 @@ class EditDetails extends ViewsFormBase {
'#title' => $this->t('View tag'),
'#description' => $this->t('Optionally, enter a comma delimited list of tags for this view to use in filtering and sorting views on the administrative page.'),
'#default_value' => $view->get('tag'),
'#autocomplete_path' => 'admin/views/ajax/autocomplete/tag',
'#autocomplete_route_name' => 'views_ui.autocomplete',
);
$form['details']['description'] = array(
'#type' => 'textfield',