diff --git a/core/core.api.php b/core/core.api.php index 639e55d..4e4af63 100644 --- a/core/core.api.php +++ b/core/core.api.php @@ -2303,16 +2303,16 @@ function hook_validation_constraint_alter(array &$definitions) { * Ajax event. More information on callbacks is below in @ref sub_callback. * - wrapper: The HTML 'id' attribute of the area where the content returned by * the callback should be placed. Note that callbacks have a choice of - * returning content or JavaScript commands; 'wrapper' is used for content + * returning content or JavaScript commands; 'wrapper_selector' is used for content * returns. * - method: The jQuery method for placing the new content (used with - * 'wrapper'). Valid options are 'replaceWith' (default), 'append', 'prepend', + * 'wrapper_selector'). Valid options are 'replaceWith' (default), 'append', 'prepend', * 'before', 'after', or 'html'. See * http://api.jquery.com/category/manipulation/ for more information on these * methods. * - effect: The jQuery effect to use when placing the new HTML (used with - * 'wrapper'). Valid options are 'none' (default), 'slide', or 'fade'. - * - speed: The effect speed to use (used with 'effect' and 'wrapper'). Valid + * 'wrapper_selector'). Valid options are 'none' (default), 'slide', or 'fade'. + * - speed: The effect speed to use (used with 'effect' and 'wrapper_selector'). Valid * options are 'slow' (default), 'fast', or the number of milliseconds the * effect should run. * - event: The JavaScript event to respond to. This is selected automatically @@ -2354,7 +2354,7 @@ function hook_validation_constraint_alter(array &$definitions) { * Once you have processed the input, you have your choice of returning HTML * markup or a set of Ajax commands. If you choose to return HTML markup, you * can return it as a string or a renderable array, and it will be placed in - * the defined 'wrapper' element (see documentation above in @ref sub_form). + * the defined 'wrapper_selector' element (see documentation above in @ref sub_form). * In addition, any messages returned by drupal_get_messages(), themed as in * status-messages.html.twig, will be prepended. * @@ -2378,7 +2378,7 @@ function hook_validation_constraint_alter(array &$definitions) { * invokes an arbitrary jQuery command. * * As noted above, status messages are prepended automatically if you use the - * 'wrapper' method and return HTML markup. This is not the case if you return + * 'wrapper_selector' method and return HTML markup. This is not the case if you return * commands, but if you would like to show status messages, you can add * @code * array('#type' => 'status_messages') diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index 63bd90d..32ff5e5 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -594,7 +594,7 @@ public static function fieldSettingsAjaxProcessElement(&$element, $main_form) { if (!empty($element['#ajax'])) { $element['#ajax'] = array( 'callback' => array(get_called_class(), 'settingsAjax'), - 'wrapper' => $main_form['#id'], + 'wrapper_selector' => '#' . $main_form['#id'], 'element' => $main_form['#array_parents'], ); } diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php index dfb3c08..b4d883e 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -236,7 +236,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f '#submit' => array(array(get_class($this), 'addMoreSubmit')), '#ajax' => array( 'callback' => array(get_class($this), 'addMoreAjax'), - 'wrapper' => $wrapper_id, + 'wrapper_selector' => '#' . $wrapper_id, 'effect' => 'fade', ), ); diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index 1f39e10..7c8acba 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -243,7 +243,7 @@ public static function processAjaxForm(&$element, FormStateInterface $form_state * - #ajax['url'] * - #ajax['callback'] * - #ajax['options'] - * - #ajax['wrapper'] + * - #ajax['wrapper_selector'] * - #ajax['parameters'] * - #ajax['effect'] * - #ajax['accepts'] @@ -327,6 +327,12 @@ public static function preRenderAjaxForm($element) { $settings = $element['#ajax']; + // @todo Remove support for 'wrapper' and solely use 'wrapper_selector'. + if (isset($settings['wrapper'])) { + $settings['wrapper_selector'] = '#' . $settings['wrapper']; + unset($settings['wrapper']); + } + // Assign default settings. When 'url' is set to NULL, ajax.js submits the // Ajax request to the same URL as the form or link destination is for // someone with JavaScript disabled. This is generally preferred as a way to diff --git a/core/misc/ajax.js b/core/misc/ajax.js index fefe9f3..ad4a7ec 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -7,7 +7,7 @@ * then executed to make any changes that are necessary to the page. * * Drupal uses this file to enhance form elements with `#ajax['url']` and - * `#ajax['wrapper']` properties. If set, this file will automatically be + * `#ajax['wrapper_selector']` properties. If set, this file will automatically be * included to provide Ajax capabilities. */ @@ -323,7 +323,7 @@ function loadAjaxBehavior(base) { * then executed to make any changes that are necessary to the page. * * Drupal uses this file to enhance form elements with `#ajax['url']` and - * `#ajax['wrapper']` properties. If set, this file will automatically be + * `#ajax['wrapper_selector']` properties. If set, this file will automatically be * included to provide Ajax capabilities. * * @constructor @@ -365,16 +365,20 @@ function loadAjaxBehavior(base) { */ this.instanceIndex = false; - // @todo Remove this after refactoring the PHP code to: - // - Call this 'selector'. - // - Include the '#' for ID-based selectors. - // - Support non-ID-based selectors. + // @todo Remove support for 'wrapper' and solely use 'wrapper_selector'. if (this.wrapper) { /** + * @deprecated Use this.wrapper_selector. + * * @type {string} */ - this.wrapper = '#' + this.wrapper; + this.wrapper = null; + + /** + * @type {string} + */ + this.wrapper_selector = '#' + this.wrapper; } /** @@ -954,7 +958,7 @@ else if (type === 'fade') { this.progress.object.stopMonitoring(); } // Undo hide. - $(this.wrapper).show(); + $(this.wrapper_selector).show(); // Re-enable the element. $(this.element).prop('disabled', false); // Reattach behaviors, if they were detached in beforeSerialize(). @@ -1017,7 +1021,7 @@ else if (type === 'fade') { insert: function (ajax, response, status) { // Get information from the response. If it is not there, default to // our presets. - var $wrapper = response.selector ? $(response.selector) : $(ajax.wrapper); + var $wrapper = response.selector ? $(response.selector) : $(ajax.wrapper_selector); var method = response.method || ajax.method; var effect = ajax.getEffect(response); var settings; @@ -1077,7 +1081,7 @@ else if (effect.showEffect !== 'show') { // Attach all JavaScript behaviors to the new content, if it was // successfully added to the page, this if statement allows - // `#ajax['wrapper']` to be optional. + // `#ajax['wrapper_selector']` to be optional. if ($new_content.parents('html').length > 0) { // Apply any settings from the returned JSON if available. settings = response.settings || ajax.settings || drupalSettings; diff --git a/core/misc/dialog/dialog.ajax.js b/core/misc/dialog/dialog.ajax.js index 3f1b0c2..9c9ad7e 100644 --- a/core/misc/dialog/dialog.ajax.js +++ b/core/misc/dialog/dialog.ajax.js @@ -120,8 +120,8 @@ $dialog = $('
').appendTo('body'); } // Set up the wrapper, if there isn't one. - if (!ajax.wrapper) { - ajax.wrapper = $dialog.attr('id'); + if (!ajax.selector) { + ajax.selector = '#' + $dialog.attr('id'); } // Use the ajax.js insert command to populate the dialog contents. diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 42dfbc3..f46f6f5 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -175,7 +175,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $theme, '#ajax' => array( 'callback' => '::themeSwitch', - 'wrapper' => 'edit-block-region-wrapper', + 'wrapper_selector' => '#edit-block-region-wrapper', ), ); } diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index 60754be..f04a99a 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -226,7 +226,7 @@ public function addFormElements(array $form, FormStateInterface $form_state, Nod '#attributes' => array('class' => array('book-title-select')), '#ajax' => array( 'callback' => 'book_form_update', - 'wrapper' => 'edit-book-plid-wrapper', + 'wrapper_selector' => '#edit-book-plid-wrapper', 'effect' => 'fade', 'speed' => 'fast', ), diff --git a/core/modules/config/src/Form/ConfigSingleExportForm.php b/core/modules/config/src/Form/ConfigSingleExportForm.php index 9df8069..f801ec7 100644 --- a/core/modules/config/src/Form/ConfigSingleExportForm.php +++ b/core/modules/config/src/Form/ConfigSingleExportForm.php @@ -92,7 +92,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $config_t '#default_value' => $config_type, '#ajax' => array( 'callback' => '::updateConfigurationType', - 'wrapper' => 'edit-config-type-wrapper', + 'wrapper_selector' => '#edit-config-type-wrapper', ), ); $default_type = $form_state->getValue('config_type', $config_type); @@ -105,7 +105,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $config_t '#suffix' => '
', '#ajax' => array( 'callback' => '::updateExport', - 'wrapper' => 'edit-export-wrapper', + 'wrapper_selector' => '#edit-export-wrapper', ), ); diff --git a/core/modules/config/tests/config_test/src/ConfigTestForm.php b/core/modules/config/tests/config_test/src/ConfigTestForm.php index 8a375b8..4182d74 100644 --- a/core/modules/config/tests/config_test/src/ConfigTestForm.php +++ b/core/modules/config/tests/config_test/src/ConfigTestForm.php @@ -99,7 +99,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $size, '#ajax' => array( 'callback' => '::updateSize', - 'wrapper' => 'size-wrapper', + 'wrapper_selector' => '#size-wrapper', ), ); $form['size_wrapper']['size_submit'] = array( diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 8df1f04..8923b70 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -130,7 +130,7 @@ function editor_form_filter_format_form_alter(&$form, FormStateInterface $form_s '#ajax' => array( 'trigger_as' => array('name' => 'editor_configure'), 'callback' => 'editor_form_filter_admin_form_ajax', - 'wrapper' => 'editor-settings-wrapper', + 'wrapper_selector' => '#editor-settings-wrapper', ), '#weight' => -10, ); @@ -142,7 +142,7 @@ function editor_form_filter_format_form_alter(&$form, FormStateInterface $form_s '#submit' => array('editor_form_filter_admin_format_editor_configure'), '#ajax' => array( 'callback' => 'editor_form_filter_admin_form_ajax', - 'wrapper' => 'editor-settings-wrapper', + 'wrapper_selector' => '#editor-settings-wrapper', ), '#weight' => -10, '#attributes' => array('class' => array('js-hide')), diff --git a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php index 4b9a85d..c9bc76c 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php @@ -235,7 +235,7 @@ public function form(array $form, FormStateInterface $form_state) { '#submit' => array('::multistepSubmit'), '#ajax' => array( 'callback' => '::multistepAjax', - 'wrapper' => 'field-display-overview-wrapper', + 'wrapper_selector' => '#field-display-overview-wrapper', 'effect' => 'fade', // The button stays hidden, so we hide the Ajax spinner too. Ad-hoc // spinners will be added manually by the client-side script. @@ -347,7 +347,7 @@ protected function buildFieldRow(FieldDefinitionInterface $field_definition, arr '#submit' => array('::multistepSubmit'), '#ajax' => array( 'callback' => '::multistepAjax', - 'wrapper' => 'field-display-overview-wrapper', + 'wrapper_selector' => '#field-display-overview-wrapper', 'effect' => 'fade', ), '#field_name' => $field_name, diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php index f465b18..c26510b 100644 --- a/core/modules/file/src/Element/ManagedFile.php +++ b/core/modules/file/src/Element/ManagedFile.php @@ -226,7 +226,7 @@ public static function processManagedFile(&$element, FormStateInterface $form_st 'element_parents' => implode('/', $element['#array_parents']), ], ], - 'wrapper' => $ajax_wrapper_id, + 'wrapper_selector' => '#' . $ajax_wrapper_id, 'effect' => 'fade', 'progress' => [ 'type' => $element['#progress_indicator'], diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index b2386b4..36583be 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -411,11 +411,11 @@ public static function process($element, FormStateInterface $form_state, $form) ), ); $field_element = NestedArray::getValue($form, $parents); - $new_wrapper = $field_element['#id'] . '-ajax-wrapper'; + $new_wrapper = '#' . $field_element['#id'] . '-ajax-wrapper'; foreach (Element::children($element) as $key) { if (isset($element[$key]['#ajax'])) { $element[$key]['#ajax']['options'] = $new_options; - $element[$key]['#ajax']['wrapper'] = $new_wrapper; + $element[$key]['#ajax']['wrapper_selector'] = $new_wrapper; } } unset($element['#prefix'], $element['#suffix']); diff --git a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php index 3e5b051..8afd4ba 100644 --- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php @@ -98,7 +98,7 @@ public function form(array $form, FormStateInterface $form_state) { '#description' => $description, '#ajax' => array( 'callback' => '::breakpointMappingFormAjax', - 'wrapper' => 'responsive-image-style-breakpoints-wrapper', + 'wrapper_selector' => '#responsive-image-style-breakpoints-wrapper', ), ); diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 3622642..c532214 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -1747,10 +1747,16 @@ protected function drupalProcessAjaxResponse($content, array $ajax_response, arr case 'insert': $wrapperNode = NULL; - // When a command doesn't specify a selector, use the - // #ajax['wrapper'] which is always an HTML ID. + // When a command doesn't specify a selector, use #ajax['wrapper_selector']. if (!isset($command['selector'])) { - $wrapperNode = $xpath->query('//*[@id="' . $ajax_settings['wrapper'] . '"]')->item(0); + $selector_type = substr($ajax_settings['wrapper_selector'], 0, 1); + $selector = substr($ajax_settings['wrapper_selector'], 1); + if ($selector_type === '#') { + $wrapperNode = $xpath->query('//*[@id="' . $selector . '"]')->item(0); + } + else { + $wrapperNode = $xpath->query('//*[@class="' . $selector . '"]')->item(0); + } } // @todo Ajax commands can target any jQuery selector, but these are // hard to fully emulate with XPath. For now, just handle 'head' diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php index 19aaaf3..7fe83c7 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php @@ -35,7 +35,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'submit', '#value' => $this->t('Submit'), '#ajax' => array( - 'wrapper' => 'ajax-forms-test-lazy-load-ajax-wrapper', + 'wrapper_selector' => '#ajax-forms-test-lazy-load-ajax-wrapper', 'callback' => 'ajax_forms_test_lazy_load_form_ajax', ), '#prefix' => '
', diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php index 8ec5b71..f79c6cb 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php @@ -83,7 +83,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => $this->t('AJAX checkbox in a group'), '#ajax' => [ 'callback' => [$object, 'checkboxGroupCallback'], - 'wrapper' => 'checkbox-wrapper', + 'wrapper_selector' => '#checkbox-wrapper', ], ], 'nested_group' => [ @@ -97,7 +97,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => $this->t('AJAX checkbox in a nested group'), '#ajax' => [ 'callback' => [$object, 'checkboxGroupCallback'], - 'wrapper' => 'checkbox-wrapper', + 'wrapper_selector' => '#checkbox-wrapper', ], ], ]; diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php index dbf0b7f..1ca4531 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php @@ -28,7 +28,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $form_state->getValue('drivertext', ''), '#ajax' => array( 'callback' => 'ajax_forms_test_validation_form_callback', - 'wrapper' => 'message_area', + 'wrapper_selector' => '#message_area', 'method' => 'replace', ), '#suffix' => '
', @@ -41,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $form_state->getValue('drivernumber', ''), '#ajax' => array( 'callback' => 'ajax_forms_test_validation_number_form_callback', - 'wrapper' => 'message_area_number', + 'wrapper_selector' => '#message_area_number', 'method' => 'replace', ), '#suffix' => '
', diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php b/core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php index aa50cc4..7302ac8 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Plugin/Block/AjaxFormBlock.php @@ -84,7 +84,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ], '#ajax' => [ 'callback' => '::updateOptions', - 'wrapper' => 'edit-test1-wrapper', + 'wrapper_selector' => '#edit-test1-wrapper', ], '#prefix' => '
', '#suffix' => '
', diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase.php index 4431460..8c7a656 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase.php @@ -38,7 +38,7 @@ function tableselectFormBuilder($form, FormStateInterface $form_state, $element_ '#empty' => t('Empty text.'), '#ajax' => array( 'callback' => 'form_test_tableselect_ajax_callback', - 'wrapper' => 'tableselect-wrapper', + 'wrapper_selector' => '#tableselect-wrapper', ), ); diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index fd031d2..81ff2b3 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -54,7 +54,7 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa // to request so that the wrapper can be recognized by the AJAX system and // its content can be dynamically updated. So instead, we will keep track of // duplicate IDs (within a single request) on our own, later in this function. - $triggering_element['#ajax']['wrapper'] = 'edit-view-' . implode('-', $refresh_parents) . '-wrapper'; + $triggering_element['#ajax']['wrapper_selector'] = '#edit-view-' . implode('-', $refresh_parents) . '-wrapper'; // Add a submit button for users who do not have JavaScript enabled. It // should be displayed next to the triggering element on the form. @@ -107,11 +107,11 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa // Attach custom data to the triggering element and submit button, so we can // use it in both the process function and AJAX callback. $ajax_data = array( - 'wrapper' => $triggering_element['#ajax']['wrapper'], + 'wrapper_selector' => $triggering_element['#ajax']['wrapper_selector'], 'trigger_key' => $trigger_key, 'refresh_parents' => $refresh_parents, ); - $seen_ids[$triggering_element['#ajax']['wrapper']] = TRUE; + $seen_ids[$triggering_element['#ajax']['wrapper_selector']] = TRUE; $triggering_element['#views_ui_ajax_data'] = $ajax_data; $wrapping_element[$button_key]['#views_ui_ajax_data'] = $ajax_data; } @@ -164,7 +164,7 @@ function views_ui_add_ajax_wrapper($element, FormStateInterface $form_state) { // The HTML ID that AJAX expects was also stored in a property on the // element, so use that information to insert the wrapper
here. - $id = $element['#views_ui_ajax_data']['wrapper']; + $id = substr($element['#views_ui_ajax_data']['wrapper_selector'], 1); $refresh_element += array( '#prefix' => '', '#suffix' => '', diff --git a/core/modules/views_ui/js/ajax.js b/core/modules/views_ui/js/ajax.js index d4ff764..489a1da 100644 --- a/core/modules/views_ui/js/ajax.js +++ b/core/modules/views_ui/js/ajax.js @@ -210,7 +210,7 @@ return true; } - element_settings.wrapper = 'views-preview-wrapper'; + element_settings.wrapper_selector = '.views-preview-wrapper'; element_settings.method = 'replaceWith'; element_settings.base = $(this).attr('id'); element_settings.element = this; @@ -234,7 +234,7 @@ return true; } - element_settings.wrapper = 'views-preview-wrapper'; + element_settings.wrapper_selector = '.views-preview-wrapper'; element_settings.method = 'replaceWith'; element_settings.event = 'click'; element_settings.base = $(this).attr('id'); diff --git a/core/modules/views_ui/src/Tests/PreviewTest.php b/core/modules/views_ui/src/Tests/PreviewTest.php index d2dcd12..32b0491 100644 --- a/core/modules/views_ui/src/Tests/PreviewTest.php +++ b/core/modules/views_ui/src/Tests/PreviewTest.php @@ -320,7 +320,7 @@ protected function clickPreviewLinkAJAX($url, $row_count) { $content = $this->content; $drupal_settings = $this->drupalSettings; $ajax_settings = array( - 'wrapper' => 'views-preview-wrapper', + 'wrapper_selector' => '.views-preview-wrapper', 'method' => 'replaceWith', ); $url = $this->getAbsoluteUrl($url); diff --git a/core/modules/views_ui/src/ViewPreviewForm.php b/core/modules/views_ui/src/ViewPreviewForm.php index 7b77929..0a46023 100644 --- a/core/modules/views_ui/src/ViewPreviewForm.php +++ b/core/modules/views_ui/src/ViewPreviewForm.php @@ -16,7 +16,7 @@ class ViewPreviewForm extends ViewFormBase { public function form(array $form, FormStateInterface $form_state) { $view = $this->entity; - $form['#prefix'] = '
'; + $form['#prefix'] = '
'; $form['#suffix'] = '
'; $form['#id'] = 'views-ui-preview-form'; @@ -85,7 +85,7 @@ protected function actions(array $form, FormStateInterface $form_state) { '#id' => 'preview-submit', '#ajax' => array( 'url' => Url::fromRoute('entity.view.preview_form', ['view' => $view->id(), 'display_id' => $this->displayID]), - 'wrapper' => 'views-preview-wrapper', + 'wrapper_selector' => '.views-preview-wrapper', 'event' => 'click', 'progress' => array('type' => 'fullscreen'), 'method' => 'replaceWith', diff --git a/core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php b/core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php index 3b52f9a..118fe56 100644 --- a/core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Element/RenderElementTest.php @@ -44,33 +44,70 @@ protected function setUp() { /** * @covers ::preRenderAjaxForm + * @dataProvider providerTestPreRenderAjaxForm */ - public function testPreRenderAjaxForm() { + public function testPreRenderAjaxForm($element, $expected, $url) { $request = Request::create('/test'); $request->query->set('foo', 'bar'); $this->requestStack->push($request); $prophecy = $this->prophesize('Drupal\Core\Routing\UrlGeneratorInterface'); - $url = '/test?foo=bar&ajax_form=1'; $prophecy->generateFromRoute('', [], ['query' => ['foo' => 'bar', FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]], TRUE) ->willReturn((new GeneratedUrl())->setCacheContexts(['route'])->setGeneratedUrl($url)); $url_generator = $prophecy->reveal(); $this->container->set('url_generator', $url_generator); - $element = [ - '#type' => 'select', - '#id' => 'test', - '#ajax' => [ - 'wrapper' => 'foo', + + $result = RenderElement::preRenderAjaxForm($element); + + $this->assertTrue($result['#ajax_processed']); + $this->assertSame($expected, $result['#attached']['drupalSettings']['ajax']['test']); + } + + /** + * Provides test data for testPreRenderAjaxForm(). + */ + public function providerTestPreRenderAjaxForm() { + $data = []; + $data['wrapper_selector'] = [ + [ + '#type' => 'select', + '#id' => 'test', + '#ajax' => [ + 'wrapper_selector' => '#foo', + 'callback' => 'test-callback', + ], + ], + [ + 'wrapper_selector' => '#foo', 'callback' => 'test-callback', + 'event' => 'change', + 'url' => '/test?foo=bar&ajax_form=1', + 'dialogType' => 'ajax', ], + '/test?foo=bar&ajax_form=1', ]; - - $element = RenderElement::preRenderAjaxForm($element); - - $this->assertTrue($element['#ajax_processed']); - $this->assertEquals($url, $element['#attached']['drupalSettings']['ajax']['test']['url']); + // @todo Remove support for 'wrapper' and solely use 'wrapper_selector'. + $data['wrapper'] = [ + [ + '#type' => 'select', + '#id' => 'test', + '#ajax' => [ + 'wrapper' => 'foo', + 'callback' => 'test-callback', + ], + ], + [ + 'callback' => 'test-callback', + 'event' => 'change', + 'wrapper_selector' => '#foo', + 'url' => '/test?foo=bar&ajax_form=1', + 'dialogType' => 'ajax', + ], + '/test?foo=bar&ajax_form=1', + ]; + return $data; } /** @@ -93,7 +130,7 @@ public function testPreRenderAjaxFormWithQueryOptions() { '#type' => 'select', '#id' => 'test', '#ajax' => [ - 'wrapper' => 'foo', + 'wrapper_selector' => '#foo', 'callback' => 'test-callback', 'options' => [ 'query' => [