From 0a1b1dc9bb3248788a93aa45bb255cd0dbddaeab Mon Sep 17 00:00:00 2001
From: damiankloip <damiankloip@1037976.no-reply.drupal.org>
Date: Fri, 12 Oct 2012 11:42:07 +0200
Subject: [PATCH] Issue #1810788 by damiankloip: Added enable and disable
 procedural wrappers.

---
 lib/Drupal/views/Tests/ModuleTest.php         | 17 +++++++++++
 .../config/views.view.test_view_status.yml    | 16 ++++++++++
 views.module                                  | 29 ++++++++++++++++---
 3 files changed, 58 insertions(+), 4 deletions(-)
 create mode 100644 tests/views_test_config/config/views.view.test_view_status.yml

diff --git a/lib/Drupal/views/Tests/ModuleTest.php b/lib/Drupal/views/Tests/ModuleTest.php
index 070a6293005f..e2365a21fc15 100644
--- a/lib/Drupal/views/Tests/ModuleTest.php
+++ b/lib/Drupal/views/Tests/ModuleTest.php
@@ -175,6 +175,23 @@ public function testLoadFunctions() {
     $this->assertIdentical($expected_opt_groups, views_get_views_as_options(FALSE, 'all', NULL, TRUE), 'Expected option array for an option group returned.');
   }
 
+  /**
+   * Tests view enable and disable procedural wrapper functions.
+   */
+  function testStatusFunctions() {
+    $view = views_get_view('test_view_status')->storage;
+
+    $this->assertFalse($view->isEnabled(), 'The view status is disabled.');
+
+    views_enable_view($view);
+    $this->assertTrue($view->isEnabled(), 'A view has been enabled.');
+    $this->assertEqual($view->isEnabled(), views_view_is_enabled($view), 'views_view_is_enabled is correct.');
+
+    views_disable_view($view);
+    $this->assertFalse($view->isEnabled(), 'A view has been disabled.');
+    $this->assertEqual(!$view->isEnabled(), views_view_is_disabled($view), 'views_view_is_disabled is correct.');
+  }
+
   /**
    * Helper to return an expected views option array.
    *
diff --git a/tests/views_test_config/config/views.view.test_view_status.yml b/tests/views_test_config/config/views.view.test_view_status.yml
new file mode 100644
index 000000000000..08261f55df31
--- /dev/null
+++ b/tests/views_test_config/config/views.view.test_view_status.yml
@@ -0,0 +1,16 @@
+base_table: views_test_data
+name: test_view_status
+description: ''
+tag: ''
+human_name: test_view_status
+core: 8.x
+api_version: '3.0'
+display:
+  default:
+    display_plugin: default
+    id: default
+    display_title: Master
+    position: ''
+base_field: id
+disabled: '1'
+module: views
diff --git a/views.module b/views.module
index e20d3f8a20de..8f5b877ecf0e 100644
--- a/views.module
+++ b/views.module
@@ -12,6 +12,7 @@
 use Drupal\Core\Database\Query\AlterableInterface;
 use Drupal\views\ViewExecutable;
 use Drupal\Component\Plugin\Exception\PluginException;
+use Drupal\views\ViewStorage;
 
 /**
  * Views API version string.
@@ -1633,29 +1634,49 @@ function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclu
 /**
  * Returns whether the view is enabled.
  *
- * @param Drupal\views\ViewExecutable $view
+ * @param Drupal\views\ViewStorage $view
  *   The view object to check.
  *
  * @return bool
  *   Returns TRUE if a view is enabled, FALSE otherwise.
  */
-function views_view_is_enabled($view) {
+function views_view_is_enabled(ViewStorage $view) {
   return $view->isEnabled();
 }
 
 /**
  * Returns whether the view is disabled.
  *
- * @param Drupal\views\ViewExecutable $view
+ * @param Drupal\views\ViewStorage $view
  *   The view object to check.
  *
  * @return bool
  *   Returns TRUE if a view is disabled, FALSE otherwise.
  */
-function views_view_is_disabled($view) {
+function views_view_is_disabled(ViewStorage $view) {
   return !$view->isEnabled();
 }
 
+/**
+ * Enables a view.
+ *
+ * @param Drupal\views\ViewStorage $view
+ *   The ViewStorage object to disable.
+ */
+function views_enable_view(ViewStorage $view) {
+  $view->enable();
+}
+
+/**
+ * Disables a view.
+ *
+ * @param Drupal\views\ViewStorage $view
+ *   The ViewStorage object to disable.
+ */
+function views_disable_view(ViewStorage $view) {
+  $view->disable();
+}
+
 /**
  * Loads a view from configuration.
  *
-- 
GitLab