Skip to content
Snippets Groups Projects
Commit a3887c83 authored by Damian Lee's avatar Damian Lee Committed by Tim Plunkett
Browse files

Added save method to controller, with static property array so all views properties aren't saved

parent 662298a2
No related branches found
No related tags found
No related merge requests found
<?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');
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment