From 3edf19ce631a6917049f7fd6284fc3431437c1ee Mon Sep 17 00:00:00 2001
From: Daniel Wehner <daniel.wehner@erdfisch.de>
Date: Mon, 27 Aug 2012 16:46:07 +0200
Subject: [PATCH] Change the status of a view in the UI

---
 plugins/export_ui/views_ui.class.php |  8 +++++++-
 views.install                        |  1 +
 views.module                         | 27 ++++++++++++++++++++++++++-
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/plugins/export_ui/views_ui.class.php b/plugins/export_ui/views_ui.class.php
index f8f1f1c9c1c5..eb334a319427 100644
--- a/plugins/export_ui/views_ui.class.php
+++ b/plugins/export_ui/views_ui.class.php
@@ -361,7 +361,13 @@ function add_template_page($js, $input, $name, $step = NULL) {
   }
 
   function set_item_state($state, $js, $input, $item) {
-    ctools_export_set_object_status($item, $state);
+    if (!$state) {
+      $item->enable();
+    }
+    else {
+      $item->disable();
+    }
+    $item->save();
     menu_router_rebuild();
 
     if (!$js) {
diff --git a/views.install b/views.install
index 826d98d3ec08..149e524487da 100644
--- a/views.install
+++ b/views.install
@@ -38,6 +38,7 @@ function views_schema() {
       'load all callback' => 'views_get_all_views',
       'load callback' => 'views_storage_load',
       'save callback' => 'views_storage_save',
+      'status callback' => 'views_storage_status',
       'subrecords callback' => 'views_load_display_records',
       // the variable that holds enabled/disabled status
       'status' => 'views_defaults',
diff --git a/views.module b/views.module
index e17fa825fd29..72416dc3c536 100644
--- a/views.module
+++ b/views.module
@@ -1575,7 +1575,7 @@ function views_get_all_views($reset = FALSE) {
 }
 
 /**
- * Loads a view with the storage controller.
+ * Load a view with the storage controller.
  *
  * @param string $id
  *   The view name to load.
@@ -1589,11 +1589,36 @@ function views_storage_load($id) {
   return reset($result);
 }
 
+/**
+ * Save a view with the storage controller.
+ *
+ * @param Drupal\views\View $view
+ *   The view which is saved.
+ *
+ * @return
+ *   SAVED_NEW or SAVED_UPDATED is returned depending on the operation
+ *   performed.
+ */
 function views_storage_save(View $view) {
   $controller = entity_get_controller('view');
   return $controller->save($view);
 }
 
+/**
+ * Change the status of a view.
+ *
+ * @param Drupal\views\View $view
+ *   The view which gets a different status.
+ */
+function views_storage_status(View $view, $status) {
+  if (!$status) {
+    $view->enable();
+  }
+  else {
+    $view->disable();
+  }
+}
+
 /**
  * Returns an array of all enabled views, as fully loaded $view objects.
  */
-- 
GitLab