From a3887c83d69ba6c631639b4af95a854aaa0d6d06 Mon Sep 17 00:00:00 2001
From: damiankloip <damian@damoweb.co.uk>
Date: Sun, 26 Aug 2012 09:46:58 +0200
Subject: [PATCH] Added save method to controller, with static property array
 so all views properties aren't saved

---
 lib/Drupal/views/ViewStorage.php           |  4 +-
 lib/Drupal/views/ViewStorageController.php | 65 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/lib/Drupal/views/ViewStorage.php b/lib/Drupal/views/ViewStorage.php
index 7f7505e4f801..337235818c61 100644
--- a/lib/Drupal/views/ViewStorage.php
+++ b/lib/Drupal/views/ViewStorage.php
@@ -1,4 +1,4 @@
-  <?php
+<?php
 
 /**
  * @file
@@ -11,7 +11,7 @@
 
 class ViewStorage extends ConfigurableBase {
 
-  public function __construct() {
+  public function __construct(array $values, $entity_type) {
     parent::__construct($values, 'view');
   }
 
diff --git a/lib/Drupal/views/ViewStorageController.php b/lib/Drupal/views/ViewStorageController.php
index ffad4a47be23..9f8944f4ae10 100644
--- a/lib/Drupal/views/ViewStorageController.php
+++ b/lib/Drupal/views/ViewStorageController.php
@@ -8,6 +8,7 @@
 namespace Drupal\views;
 
 use Drupal\config\ConfigStorageController;
+use Drupal\entity\StorableInterface;
 
 class ViewStorageController extends ConfigStorageController {
 
@@ -23,4 +24,68 @@ protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
     }
   }
 
+  /**
+   * Overrides Drupal\config\ConfigStorageController::save().
+   *
+   * This currently replaces the reflection code with a static array of
+   * properties to be set on the config object. This can be removed
+   * when the view storage is isolated so the ReflectionClass can work.
+   */
+  public function save(StorableInterface $entity) {
+    $prefix = $this->entityInfo['config prefix'] . '.';
+
+    // Load the stored entity, if any.
+    if ($entity->getOriginalID()) {
+      $id = $entity->getOriginalID();
+    }
+    else {
+      $id = $entity->id();
+    }
+    $config = config($prefix . $id);
+    $config->setName($prefix . $entity->id());
+
+    if (!$config->isNew() && !isset($entity->original)) {
+      $entity->original = entity_load_unchanged($this->entityType, $id);
+    }
+
+    $this->preSave($entity);
+    $this->invokeHook('presave', $entity);
+
+    // TODO: This temp measure will be removed once we have a better way or
+    // separation of storage and the executed view.
+    $properties = array (
+      'disabled',
+      'api_version',
+      'name',
+      'description',
+      'tag',
+      'base_table',
+      'human_name',
+      'core',
+      'display',
+    );
+
+    foreach ($properties as $property) {
+      $config->set($property, $entity->$property);
+    }
+
+    if (!$config->isNew()) {
+      $return = SAVED_NEW;
+      $config->save();
+      $this->postSave($entity, TRUE);
+      $this->invokeHook('update', $entity);
+    }
+    else {
+      $return = SAVED_UPDATED;
+      $config->save();
+      $entity->enforceIsNew(FALSE);
+      $this->postSave($entity, FALSE);
+      $this->invokeHook('insert', $entity);
+    }
+
+    unset($entity->original);
+
+    return $return;
+  }
+
 }
\ No newline at end of file
-- 
GitLab