diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index dade1dfa7d433f4ea4c6c3825622ed5fd828fd79..c0cd5d03719a4d32f5055a8b233f47ff4c6bf5be 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -412,7 +412,6 @@ protected function showBuildGroupButton(&$form, FormStateInterface $form_state) '#type' => 'submit', '#value' => $this->t('Grouped filters'), '#submit' => array(array($this, 'buildGroupForm')), - '#attributes' => array('class' => array('use-ajax-submit')), ); $form['group_button']['radios']['radios']['#default_value'] = 0; } @@ -422,7 +421,6 @@ protected function showBuildGroupButton(&$form, FormStateInterface $form_state) '#type' => 'submit', '#value' => $this->t('Single filter'), '#submit' => array(array($this, 'buildGroupForm')), - '#attributes' => array('class' => array('use-ajax-submit')), ); $form['group_button']['radios']['radios']['#default_value'] = 1; } @@ -487,7 +485,6 @@ public function showExposeButton(&$form, FormStateInterface $form_state) { '#type' => 'submit', '#value' => $this->t('Expose filter'), '#submit' => array(array($this, 'displayExposedForm')), - '#attributes' => array('class' => array('use-ajax-submit')), ); $form['expose_button']['checkbox']['checkbox']['#default_value'] = 0; } @@ -500,7 +497,6 @@ public function showExposeButton(&$form, FormStateInterface $form_state) { '#type' => 'submit', '#value' => $this->t('Hide filter'), '#submit' => array(array($this, 'displayExposedForm')), - '#attributes' => array('class' => array('use-ajax-submit')), ); $form['expose_button']['checkbox']['checkbox']['#default_value'] = 1; } @@ -1075,7 +1071,6 @@ protected function buildExposedFiltersGroupForm(&$form, FormStateInterface $form '#type' => 'submit', '#value' => $this->t('Add another item'), '#submit' => array(array($this, 'addGroupForm')), - '#attributes' => array('class' => array('use-ajax-submit')), ); $js = array(); diff --git a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php index ca595fbe2c548a510575adc3faf5addd6df155f5..db467913ae907b1c50a0b9d396ffc61d0f1269f0 100644 --- a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php +++ b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php @@ -125,7 +125,6 @@ public function showExposeButton(&$form, FormStateInterface $form_state) { '#type' => 'submit', '#value' => $this->t('Expose sort'), '#submit' => array(array($this, 'displayExposedForm')), - '#attributes' => array('class' => array('use-ajax-submit')), ); $form['expose_button']['checkbox']['checkbox']['#default_value'] = 0; } @@ -138,7 +137,6 @@ public function showExposeButton(&$form, FormStateInterface $form_state) { '#type' => 'submit', '#value' => $this->t('Hide sort'), '#submit' => array(array($this, 'displayExposedForm')), - '#attributes' => array('class' => array('use-ajax-submit')), ); $form['expose_button']['checkbox']['checkbox']['#default_value'] = 1; } diff --git a/core/modules/views_ui/js/ajax.js b/core/modules/views_ui/js/ajax.js index 0dc0a74d3380b298176a5d8ef0a6d3dd9f91bd14..b044688c30367f2ef434817f5017e855e72abd26 100644 --- a/core/modules/views_ui/js/ajax.js +++ b/core/modules/views_ui/js/ajax.js @@ -24,6 +24,38 @@ $(response.selector).addClass('hilited'); }; + /** + * Ajax command to set the form submit action in the views modal edit form. + * + * @param {Drupal.Ajax} [ajax] + * An Ajax object. + * @param {object} response + * The Ajax response. Contains .url + * @param {string} [status] + * The XHR status code? + */ + Drupal.AjaxCommands.prototype.viewsSetForm = function (ajax, response, status) { + var $form = $('.js-views-ui-dialog form'); + // Identify the button that was clicked so that .ajaxSubmit() can use it. + // We need to do this for both .click() and .mousedown() since JavaScript + // code might trigger either behavior. + var $submit_buttons = $form.find('input[type=submit].js-form-submit, button.js-form-submit').once('views-ajax-submit'); + $submit_buttons.on('click mousedown', function () { + this.form.clk = this; + }); + $form.once('views-ajax-submit').each(function () { + var $form = $(this); + var element_settings = { + url: response.url, + event: 'submit', + base: $form.attr('id'), + element: this + }; + var ajaxForm = Drupal.ajax(element_settings); + ajaxForm.$form = $form; + }); + }; + /** * Ajax command to show certain buttons in the views edit form. * diff --git a/core/modules/views_ui/src/Ajax/SetFormCommand.php b/core/modules/views_ui/src/Ajax/SetFormCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..e114529601a02e8c900ca152bd511c2e40fe3c11 --- /dev/null +++ b/core/modules/views_ui/src/Ajax/SetFormCommand.php @@ -0,0 +1,46 @@ +<?php + +/** + * @file + * Contains \Drupal\views_ui\Ajax\SetFormCommand. + */ + +namespace Drupal\views_ui\Ajax; + +use Drupal\Core\Ajax\CommandInterface; + +/** + * Provides an AJAX command for setting a form submit URL in modal forms. + * + * This command is implemented in Drupal.AjaxCommands.prototype.viewsSetForm. + */ +class SetFormCommand implements CommandInterface { + + /** + * The URL of the form. + * + * @var string + */ + protected $url; + + /** + * Constructs a SetFormCommand object. + * + * @param string $url + * The URL of the form. + */ + public function __construct($url) { + $this->url = $url; + } + + /** + * {@inheritdoc} + */ + public function render() { + return array( + 'command' => 'viewsSetForm', + 'url' => $this->url, + ); + } + +} diff --git a/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php b/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php index 8df344a832e6201b8fa216df6f65d9b3303b5e2a..e82dc423486c8d7cc572fffee1dd1c7e86d24d59 100644 --- a/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php +++ b/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php @@ -181,9 +181,6 @@ public function buildForm(array $form, FormStateInterface $form_state, Request $ '#value' => $this->t('Remove'), '#submit' => array(array($this, 'remove')), '#limit_validation_errors' => array(array('override')), - '#ajax' => array( - 'url' => Url::fromRoute('<current>'), - ), '#button_type' => 'danger', ); } diff --git a/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php b/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php index f58484cc1596a04911c5391d0a12a2813fc6a58a..478dae155bbd8e644d058dde075965137c7e986f 100644 --- a/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php +++ b/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php @@ -134,7 +134,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { 'class' => array('views-remove-group'), ), '#group' => $id, - '#ajax' => ['url' => NULL], ); } $group_options[$id] = $id == 1 ? $this->t('Default group') : $this->t('Group @group', array('@group' => $id)); diff --git a/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php index b3edb6471752cc2657da8c46d367e32e869ed00e..b5497b641779d02854b68cb5ed569f534bdc5bb8 100644 --- a/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php +++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php @@ -16,6 +16,7 @@ use Drupal\Core\Render\RenderContext; use Drupal\views\ViewEntityInterface; use Drupal\views\Ajax; +use Drupal\views_ui\Ajax as AjaxUI; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\CloseModalDialogCommand; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -242,12 +243,18 @@ protected function ajaxFormWrapper($form_class, FormStateInterface &$form_state) $display .= $output; $options = array( - 'dialogClass' => 'views-ui-dialog', + 'dialogClass' => 'views-ui-dialog js-views-ui-dialog', 'width' => '75%', ); $response->addCommand(new OpenModalDialogCommand($title, $display, $options)); + // Views provides its own custom handling of AJAX form submissions. + // Usually this happens at the same path, but custom paths may be + // specified in $form_state. + $form_url = $form_state->has('url') ? $form_state->get('url')->toString() : $this->url('<current>'); + $response->addCommand(new AjaxUI\SetFormCommand($form_url)); + if ($section = $form_state->get('#section')) { $response->addCommand(new Ajax\HighlightCommand('.' . Html::cleanCssIdentifier($section))); } diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index 33c3284233bd8580bb344ea43237b1d7dee0a686..8783c3e73d2baddc51fe6fc63d7aa79c0992c28c 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -295,11 +295,6 @@ public function getStandardButtons(&$form, FormStateInterface $form_state, $form $names = array(t('Apply'), t('Apply and continue')); } - // Views provides its own custom handling of AJAX form submissions. Usually - // this happens at the same path, but custom paths may be specified in - // $form_state. - $form_url = $form_state->get('url') ?: Url::fromRouteMatch(\Drupal::routeMatch()); - // Forms that are purely informational set an ok_button flag, so we know not // to create an "Apply" button for them. if (!$form_state->get('ok_button')) { @@ -314,9 +309,6 @@ public function getStandardButtons(&$form, FormStateInterface $form_state, $form // take care of running the regular submit handler as appropriate. '#submit' => array(array($this, 'standardSubmit')), '#button_type' => 'primary', - '#ajax' => array( - 'url' => $form_url, - ), ); // Form API button click detection requires the button's #value to be the // same between the form build of the initial page request, and the @@ -342,9 +334,6 @@ public function getStandardButtons(&$form, FormStateInterface $form_state, $form '#value' => !$form_state->get('ok_button') ? t('Cancel') : t('Ok'), '#submit' => array($cancel_submit), '#validate' => array(), - '#ajax' => array( - 'path' => $form_url, - ), '#limit_validation_errors' => array(), );