Commit b3ef8833 authored by alexpott's avatar alexpott

Issue #2248223 by olli, Lendude, peterg.griffin, finne, mikeker, pjonckiere,...

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
parent 52786985
......@@ -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;
}
......@@ -1092,7 +1088,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();
......
......@@ -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;
}
......
......@@ -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.
*
......
<?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,
);
}
}
......@@ -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',
);
}
......
......@@ -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));
......
......@@ -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)));
}
......
......@@ -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(),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment