From c24feeee54056b6b59ef5c3285c61ccff66b8f40 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Wed, 26 Feb 2014 09:26:59 -0800
Subject: [PATCH] Issue #2156853 by olli, quicksketch: Views UI Save and Cancel
 buttons break existing locks by other users.

---
 .../lib/Drupal/views_ui/Tests/CachedDataUITest.php         | 7 +++++++
 .../lib/Drupal/views_ui/ViewEditFormController.php         | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/CachedDataUITest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/CachedDataUITest.php
index 6d39784b2d72..9bfde8eed046 100644
--- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/CachedDataUITest.php
+++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/CachedDataUITest.php
@@ -60,10 +60,17 @@ public function testCacheData() {
     $this->drupalLogin($this->adminUser);
 
     $this->drupalGet('admin/structure/views/view/test_view/edit');
+    // Test that save and cancel buttons are not shown.
+    $this->assertNoFieldById('edit-actions-submit', t('Save'));
+    $this->assertNoFieldById('edit-actions-cancel', t('Cancel'));
     // Test we have the break lock link.
     $this->assertLinkByHref('admin/structure/views/view/test_view/break-lock');
     // Break the lock.
     $this->clickLink(t('break this lock'));
+    $this->drupalPostForm(NULL, array(), t('Break lock'));
+    // Test that save and cancel buttons are shown.
+    $this->assertFieldById('edit-actions-submit', t('Save'));
+    $this->assertFieldById('edit-actions-cancel', t('Cancel'));
     // Test we can save the view.
     $this->drupalPostForm('admin/structure/views/view/test_view/edit', array(), t('Save'));
     $this->assertRaw(t('The view %view has been saved.', array('%view' => 'Test view')));
diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php
index a05e0ade99cf..3c803d8459f1 100644
--- a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php
+++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php
@@ -225,6 +225,10 @@ protected function actions(array $form, array &$form_state) {
         array($this, 'cancel'),
       ),
     );
+    if ($this->entity->isLocked()) {
+      $actions['submit']['#access'] = FALSE;
+      $actions['cancel']['#access'] = FALSE;
+    }
     return $actions;
   }
 
@@ -235,6 +239,9 @@ public function validate(array $form, array &$form_state) {
     parent::validate($form, $form_state);
 
     $view = $this->entity;
+    if ($view->isLocked()) {
+      $this->setFormError('', $form_state, $this->t('Changes cannot be made to a locked view.'));
+    }
     foreach ($view->getExecutable()->validate() as $display_errors) {
       foreach ($display_errors as $error) {
         $this->setFormError('', $form_state, $error);
-- 
GitLab