Commit 625e3009 authored by tim.plunkett's avatar tim.plunkett

Issue #1766088 by tim.plunkett: Update ViewStorage* for Configurables rename.

parent 774ef63c
......@@ -36,14 +36,14 @@ class ViewStorageTest extends WebTestBase {
);
/**
* The Configurable information from entity_get_info().
* The configuration entity information from entity_get_info().
*
* @var array
*/
protected $info;
/**
* The Configurable controller.
* The configuration entity storage controller.
*
* @var Drupal\views\ViewStorageController
*/
......@@ -58,7 +58,7 @@ class ViewStorageTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Configurables CRUD tests',
'name' => 'Configuration entity CRUD tests',
'description' => 'Tests the CRUD functionality for ViewStorage.',
'group' => 'Views',
);
......@@ -67,8 +67,8 @@ public static function getInfo() {
/**
* Tests CRUD operations.
*/
function testConfigurableCRUD() {
// Get the Configurable information and controller.
function testConfigurationEntityCRUD() {
// Get the configuration entity information and controller.
$this->info = entity_get_info('view');
$this->controller = entity_get_controller('view');
......@@ -88,7 +88,7 @@ function testConfigurableCRUD() {
}
/**
* Tests loading configurables.
* Tests loading configuration entities.
*/
protected function loadTests() {
$view = $this->loadView('archive');
......@@ -113,27 +113,27 @@ protected function loadTests() {
$this->assertTrue(!empty($display_options) && is_array($display_options), 'Display options exist.');
}
// Fetch data for all Configurable objects and default view configurations.
$all_configurables = $this->controller->load();
// Fetch data for all configuration entities and default view configurations.
$all_configuration_entities = $this->controller->load();
$all_config = config_get_storage_names_with_prefix('views.view');
// Remove the 'views.view.' prefix from config names for comparision with
// loaded Configurable objects.
// loaded configuration entities.
$prefix_map = function ($value) {
$parts = explode('.', $value);
return end($parts);
};
// Check that the correct number of Configurable objects have been loaded.
$count = count($all_configurables);
$this->assertEqual($count, count($all_config), format_string('The array of all @count Configurable objects is loaded.', array('@count' => $count)));
// Check that the correct number of configuration entities have been loaded.
$count = count($all_configuration_entities);
$this->assertEqual($count, count($all_config), format_string('The array of all @count configuration entities is loaded.', array('@count' => $count)));
// Check that all of these machine names match.
$this->assertIdentical(array_keys($all_configurables), array_map($prefix_map, $all_config), 'All loaded elements match.');
$this->assertIdentical(array_keys($all_configuration_entities), array_map($prefix_map, $all_config), 'All loaded elements match.');
}
/**
* Tests creating configurables.
* Tests creating configuration entities.
*/
protected function createTests() {
// Create a new View instance with empty values.
......@@ -169,7 +169,7 @@ protected function createTests() {
}
/**
* Tests saving configurables.
* Tests saving configuration entities.
*/
protected function saveTests() {
$view = $this->loadView('archive');
......@@ -209,7 +209,7 @@ protected function saveTests() {
}
/**
* Tests deleting configurables.
* Tests deleting configuration entities.
*/
protected function deleteTests() {
$view = $this->loadView('tracker');
......@@ -222,7 +222,7 @@ protected function deleteTests() {
}
/**
* Tests adding, saving, and loading displays on configurables.
* Tests adding, saving, and loading displays on configuration entities.
*/
protected function displayTests() {
// Check whether a display can be added and saved to a View.
......@@ -247,7 +247,7 @@ protected function displayTests() {
}
/**
* Tests statuses of configurables.
* Tests statuses of configuration entities.
*/
protected function statusTests() {
// Test a View can be enabled and disabled again (with a new view).
......@@ -273,7 +273,7 @@ protected function statusTests() {
}
/**
* Loads a single Configurable object from the controller.
* Loads a single configuration entity from the controller.
*
* @param string $view_name
* The machine name of the view.
......
......@@ -7,15 +7,15 @@
namespace Drupal\views;
use Drupal\config\ConfigurableBase;
use Drupal\config\ConfigEntityBase;
/**
* Defines a ViewStorage configurable class.
* Defines a ViewStorage configuration entity class.
*/
class ViewStorage extends ConfigurableBase implements ViewStorageInterface {
class ViewStorage extends ConfigEntityBase implements ViewStorageInterface {
/**
* Overrides Drupal\entity\StorableInterface::id().
* Overrides Drupal\entity\EntityInterface::id().
*/
public function id() {
return $this->name;
......
......@@ -8,7 +8,7 @@
namespace Drupal\views;
use Drupal\config\ConfigStorageController;
use Drupal\entity\StorableInterface;
use Drupal\entity\EntityInterface;
/**
* Defines the storage controller class for ViewStorage entities.
......@@ -18,11 +18,11 @@ class ViewStorageController extends ConfigStorageController {
/**
* Overrides Drupal\config\ConfigStorageController::attachLoad();
*/
protected function attachLoad(&$queried_objects, $revision_id = FALSE) {
foreach ($queried_objects as $id => $configurable) {
protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
foreach ($queried_entities as $id => $entity) {
// @todo This property is left in for CTools export UI.
$configurable->type = t('Normal');
$this->attachDisplays($configurable);
$entity->type = t('Normal');
$this->attachDisplays($entity);
}
}
......@@ -33,25 +33,25 @@ protected function attachLoad(&$queried_objects, $revision_id = FALSE) {
* 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 $configurable) {
public function save(EntityInterface $entity) {
$prefix = $this->entityInfo['config prefix'] . '.';
// Load the stored configurable, if any, and rename it.
if ($configurable->getOriginalID()) {
$id = $configurable->getOriginalID();
// Load the stored entity, if any, and rename it.
if ($entity->getOriginalID()) {
$id = $entity->getOriginalID();
}
else {
$id = $configurable->id();
$id = $entity->id();
}
$config = config($prefix . $id);
$config->setName($prefix . $configurable->id());
$config->setName($prefix . $entity->id());
if (!$config->isNew() && !isset($configurable->original)) {
$configurable->original = entity_load_unchanged($this->entityType, $id);
if (!$config->isNew() && !isset($entity->original)) {
$entity->original = entity_load_unchanged($this->entityType, $id);
}
$this->preSave($configurable);
$this->invokeHook('presave', $configurable);
$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.
......@@ -70,7 +70,7 @@ public function save(StorableInterface $configurable) {
foreach ($config_properties as $property) {
if ($property == 'display') {
$displays = array();
foreach ($configurable->display as $key => $display) {
foreach ($entity->display as $key => $display) {
$displays[$key] = array(
'display_options' => $display->display_options,
'display_plugin' => $display->display_plugin,
......@@ -82,28 +82,28 @@ public function save(StorableInterface $configurable) {
$config->set('display', $displays);
}
else {
$config->set($property, $configurable->$property);
$config->set($property, $entity->$property);
}
}
if (!$config->isNew()) {
$return = SAVED_NEW;
$config->save();
$this->postSave($configurable, TRUE);
$this->invokeHook('update', $configurable);
$this->postSave($entity, TRUE);
$this->invokeHook('update', $entity);
}
else {
$return = SAVED_UPDATED;
$config->save();
$configurable->enforceIsNew(FALSE);
$this->postSave($configurable, FALSE);
$this->invokeHook('insert', $configurable);
$entity->enforceIsNew(FALSE);
$this->postSave($entity, FALSE);
$this->invokeHook('insert', $entity);
}
// Clear caches.
views_invalidate_cache();
unset($configurable->original);
unset($entity->original);
return $return;
}
......@@ -124,22 +124,22 @@ public function create(array $values) {
)
);
$configurable = parent::create($values);
$entity = parent::create($values);
$this->attachDisplays($configurable);
return $configurable;
$this->attachDisplays($entity);
return $entity;
}
/**
* Attaches an array of ViewDisplay objects to the view display property.
*
* @param Drupal\entity\StorableInterface $configurable
* @param Drupal\entity\EntityInterface $entity
*/
protected function attachDisplays(StorableInterface $configurable) {
if (isset($configurable->display) && is_array($configurable->display)) {
protected function attachDisplays(EntityInterface $entity) {
if (isset($entity->display) && is_array($entity->display)) {
$displays = array();
foreach ($configurable->get('display') as $key => $options) {
foreach ($entity->get('display') as $key => $options) {
$options += array(
'display_options' => array(),
'display_plugin' => NULL,
......@@ -151,7 +151,7 @@ protected function attachDisplays(StorableInterface $configurable) {
$displays[$key] = new ViewDisplay($options);
}
$configurable->set('display', $displays);
$entity->set('display', $displays);
}
}
......
......@@ -7,25 +7,25 @@
namespace Drupal\views;
use Drupal\config\ConfigurableInterface;
use Drupal\config\ConfigEntityInterface;
/**
* Defines an interface for View storage classes.
*/
interface ViewStorageInterface extends ConfigurableInterface {
interface ViewStorageInterface extends ConfigEntityInterface {
/**
* Sets the configurable entity status to enabled.
* Sets the configuration entity status to enabled.
*/
public function enable();
/**
* Sets the configurable entity status to disabled.
* Sets the configuration entity status to disabled.
*/
public function disable();
/**
* Returns whether the configurable entity is enabled.
* Returns whether the configuration entity is enabled.
*
* @return bool
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment