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
5278698510
commit
b3ef88335f
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -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',
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue