diff --git a/lib/Drupal/views/ViewStorage.php b/lib/Drupal/views/ViewStorage.php index 7f7505e4f801a08e78161822e285d12ad801e34d..337235818c61ebfb9f2cdeb3ca32d1aec4e48b88 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 ffad4a47be23a8d3d5c08abb41d4c6cacbdb87ee..9f8944f4ae10f93a185bc06b785bfcc80142a717 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