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