summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2016-03-10 16:12:56 (GMT)
committerAlex Pott2016-03-10 16:12:56 (GMT)
commitb3ef88335f1ba36641e7255a220b36935c24eb21 (patch)
treeac4738af3e61a4301d40ec045a624e4ae84ef2dc
parent52786985104424e6738e079b22b319353030af9f (diff)
Issue #2248223 by olli, Lendude, peterg.griffin, finne, mikeker, pjonckiere, b0unty, ohthehugemanatee, zniki.ru, dawehner, jhodgdon, effulgentsia, xjm, droplet, metzlerd: Adding a new Views filter and making it exposed returns user back to list of filters
-rw-r--r--core/modules/views/src/Plugin/views/filter/FilterPluginBase.php5
-rw-r--r--core/modules/views/src/Plugin/views/sort/SortPluginBase.php2
-rw-r--r--core/modules/views_ui/js/ajax.js32
-rw-r--r--core/modules/views_ui/src/Ajax/SetFormCommand.php46
-rw-r--r--core/modules/views_ui/src/Form/Ajax/ConfigHandler.php3
-rw-r--r--core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php1
-rw-r--r--core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php9
-rw-r--r--core/modules/views_ui/src/ViewUI.php11
8 files changed, 86 insertions, 23 deletions
diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
index ba8096b..75b5297 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 @@ abstract class FilterPluginBase extends HandlerBase implements CacheableDependen
'#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 @@ abstract class FilterPluginBase extends HandlerBase implements CacheableDependen
'#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 @@ abstract class FilterPluginBase extends HandlerBase implements CacheableDependen
'#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 @@ abstract class FilterPluginBase extends HandlerBase implements CacheableDependen
'#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;
}
@@ -1092,7 +1088,6 @@ abstract class FilterPluginBase extends HandlerBase implements CacheableDependen
'#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 ca595fb..db46791 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 @@ abstract class SortPluginBase extends HandlerBase implements CacheableDependency
'#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 @@ abstract class SortPluginBase extends HandlerBase implements CacheableDependency
'#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 0dc0a74..b044688 100644
--- a/core/modules/views_ui/js/ajax.js
+++ b/core/modules/views_ui/js/ajax.js
@@ -25,6 +25,38 @@
};
/**
+ * 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.
*
* @param {Drupal.Ajax} [ajax]
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 0000000..e114529
--- /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 8df344a..e82dc42 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 @@ class ConfigHandler extends ViewsFormBase {
'#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 f58484c..478dae1 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 @@ class RearrangeFilter extends ViewsFormBase {
'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 b3edb64..b5497b6 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\BubbleableMetadata;
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 @@ abstract class ViewsFormBase extends FormBase implements ViewsFormInterface {
$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 33c3284..8783c3e 100644
--- a/core/modules/views_ui/src/ViewUI.php
+++ b/core/modules/views_ui/src/ViewUI.php
@@ -295,11 +295,6 @@ class ViewUI implements ViewEntityInterface {
$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 @@ class ViewUI implements ViewEntityInterface {
// 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 @@ class ViewUI implements ViewEntityInterface {
'#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(),
);