From 1294311df81166a09491901f0937e48b7cfc825b Mon Sep 17 00:00:00 2001
From: dereine <dereine@99340.no-reply.drupal.org>
Date: Sun, 7 Oct 2012 17:22:07 +0200
Subject: [PATCH] Issue #1805540 by dawehner: Fixed All displays are marked as
 disabled all the time.

---
 lib/Drupal/views/Tests/UI/DisplayTest.php | 21 +++++++++++++++++++++
 views_ui/lib/Drupal/views_ui/ViewUI.php   |  4 ++--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lib/Drupal/views/Tests/UI/DisplayTest.php b/lib/Drupal/views/Tests/UI/DisplayTest.php
index 55d9781fdb07..cf24c746438b 100644
--- a/lib/Drupal/views/Tests/UI/DisplayTest.php
+++ b/lib/Drupal/views/Tests/UI/DisplayTest.php
@@ -145,6 +145,27 @@ public function testCloneDisplay() {
     $this->assertLinkByHref($path_prefix . '/page_1', 0, 'Make sure after cloning the new display appears in the UI');
   }
 
+  /**
+   * Tests disabling of a display.
+   */
+  public function testDisableDisplay() {
+    $view = $this->randomView();
+    $path_prefix = 'admin/structure/views/view/' . $view['name'] .'/edit';
+
+    $this->drupalGet($path_prefix);
+    $this->assertFalse($this->xpath('//div[contains(@class, :class)]', array(':class' => 'views-display-disabled')), 'Make sure the disabled display css class does not appear after initial adding of a view.');
+
+    $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-disable', '', 'Make sure the disable button is visible.');
+    $this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-enable', '', 'Make sure the enable button is not visible.');
+    $this->drupalPost(NULL, array(), 'disable Page');
+    $this->assertTrue($this->xpath('//div[contains(@class, :class)]', array(':class' => 'views-display-disabled')), 'Make sure the disabled display css class appears once the display is marked as such.');
+
+    $this->assertNoFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-disable', '', 'Make sure the disable button is not visible.');
+    $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-enable', '', 'Make sure the enable button is visible.');
+    $this->drupalPost(NULL, array(), 'enable Page');
+    $this->assertFalse($this->xpath('//div[contains(@class, :class)]', array(':class' => 'views-display-disabled')), 'Make sure the disabled display css class does not appears once the display is enabled again.');
+  }
+
   /**
    * Tests views_ui_views_plugins_display_alter is altering plugin definitions.
    */
diff --git a/views_ui/lib/Drupal/views_ui/ViewUI.php b/views_ui/lib/Drupal/views_ui/ViewUI.php
index 1c368b43ef44..df3e0fd4a0be 100644
--- a/views_ui/lib/Drupal/views_ui/ViewUI.php
+++ b/views_ui/lib/Drupal/views_ui/ViewUI.php
@@ -1376,7 +1376,7 @@ public function buildEditForm($form, &$form_state, $display_id = NULL) {
 
       // Add a text that the display is disabled.
       if (!empty($this->displayHandlers[$display_id])) {
-        if ($this->displayHandlers[$display_id]->isEnabled()) {
+        if (!$this->displayHandlers[$display_id]->isEnabled()) {
           $form['displays']['settings']['disabled']['#markup'] = t('This display is disabled.');
         }
       }
@@ -1394,7 +1394,7 @@ public function buildEditForm($form, &$form_state, $display_id = NULL) {
         $form['displays']['settings']['settings_content']['tab_content']['#attributes']['class'][] = 'views-display-deleted';
       }
       // Mark disabled displays as such.
-      if (empty($enabled)) {
+      if (!$this->displayHandlers[$display_id]->isEnabled()) {
         $form['displays']['settings']['settings_content']['tab_content']['#attributes']['class'][] = 'views-display-disabled';
       }
 
-- 
GitLab