From 77b61671cacc392417cf672ab6e71c882da46f26 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 22 Jul 2014 21:17:28 +0100 Subject: [PATCH] Issue #2305807 by amitgoyal, olli | jhodgdon: Fixed Clicking "Add" filter and then canceling dialog results in "You have unsaved changes.". --- .../views/src/Ajax/ShowButtonsCommand.php | 19 +++++++++++++++++++ core/modules/views_ui/js/ajax.js | 4 +++- .../views_ui/src/Form/Ajax/ViewsFormBase.php | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/modules/views/src/Ajax/ShowButtonsCommand.php b/core/modules/views/src/Ajax/ShowButtonsCommand.php index 92594c2aca5..28752b1158c 100644 --- a/core/modules/views/src/Ajax/ShowButtonsCommand.php +++ b/core/modules/views/src/Ajax/ShowButtonsCommand.php @@ -16,12 +16,31 @@ use Drupal\Core\Ajax\CommandInterface; */ class ShowButtonsCommand implements CommandInterface { + + /** + * Whether the view has been changed. + * + * @var bool + */ + protected $changed; + + /** + * Constructs a \Drupal\views\Ajax\ShowButtonsCommand object. + * + * @param bool $changed + * Whether the view has been changed. + */ + public function __construct($changed) { + $this->changed = $changed; + } + /** * Implements \Drupal\Core\Ajax\CommandInterface::render(). */ public function render() { return array( 'command' => 'viewsShowButtons', + 'changed' => $this->changed, ); } diff --git a/core/modules/views_ui/js/ajax.js b/core/modules/views_ui/js/ajax.js index 0d133e0fdaa..e30b4c12d5b 100644 --- a/core/modules/views_ui/js/ajax.js +++ b/core/modules/views_ui/js/ajax.js @@ -13,7 +13,9 @@ Drupal.AjaxCommands.prototype.viewsShowButtons = function (ajax, response, status) { $('div.views-edit-view div.form-actions').removeClass('js-hide'); - $('div.views-edit-view div.view-changed.messages').removeClass('js-hide'); + if (response.changed) { + $('div.views-edit-view div.view-changed.messages').removeClass('js-hide'); + } }; Drupal.AjaxCommands.prototype.viewsTriggerPreview = function (ajax, response, status) { diff --git a/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php index ecf89738436..f7d4b8687e2 100644 --- a/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php +++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php @@ -161,7 +161,7 @@ abstract class ViewsFormBase extends FormBase implements ViewsFormInterface { else { $response = new AjaxResponse(); $response->addCommand(new CloseModalDialogCommand()); - $response->addCommand(new Ajax\ShowButtonsCommand()); + $response->addCommand(new Ajax\ShowButtonsCommand(!empty($view->changed))); $response->addCommand(new Ajax\TriggerPreviewCommand()); if (!empty($form_state['#page_title'])) { $response->addCommand(new Ajax\ReplaceTitleCommand($form_state['#page_title']));