diff --git a/lib/Drupal/views/Tests/Handler/FilterDateTest.php b/lib/Drupal/views/Tests/Handler/FilterDateTest.php index b5c1ea19623fa2c59612a8c04d010221fc9845c1..1ab7cfb192b2b6eef9f1c3e85134cffb969ddf4c 100644 --- a/lib/Drupal/views/Tests/Handler/FilterDateTest.php +++ b/lib/Drupal/views/Tests/Handler/FilterDateTest.php @@ -171,6 +171,7 @@ function views_test_between() { $view->core = 8; $view->api_version = '3.0'; $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + $view->uuid = NULL; /* Display: Master */ $handler = $view->newDisplay('default', 'Master', 'default'); diff --git a/lib/Drupal/views/Tests/Plugin/PagerTest.php b/lib/Drupal/views/Tests/Plugin/PagerTest.php index 9e8602ace24a1f99147747dc5cea60907ffe09b3..01e51999bbd5aba42c93e7656ff3b7f1da12e761 100644 --- a/lib/Drupal/views/Tests/Plugin/PagerTest.php +++ b/lib/Drupal/views/Tests/Plugin/PagerTest.php @@ -112,6 +112,7 @@ public function viewsStorePagerSettings() { $view->is_cacheable = FALSE; $view->api_version = '3.0'; $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + $view->uuid = NULL; /* Display: Master */ $handler = $view->newDisplay('default', 'Master', 'default'); diff --git a/lib/Drupal/views/Tests/TranslatableTest.php b/lib/Drupal/views/Tests/TranslatableTest.php index 822b9df852ecb2065867aa6025b45da55b167635..b8c9aab7ca935d4e0327dce49c7f05351d1eca5a 100644 --- a/lib/Drupal/views/Tests/TranslatableTest.php +++ b/lib/Drupal/views/Tests/TranslatableTest.php @@ -150,6 +150,7 @@ public function view_unpack_translatable() { $view->base_table = 'node'; $view->api_version = '3.0'; $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + $view->uuid = NULL; /* Display: Master */ $handler = $view->newDisplay('default', 'Master1', 'default'); diff --git a/lib/Drupal/views/Tests/ViewStorageTest.php b/lib/Drupal/views/Tests/ViewStorageTest.php index 584612c3580bb25711860876224101a6b8ecdd80..7d3aee6346f7ca58d2c39337fed8d82df5a146ff 100644 --- a/lib/Drupal/views/Tests/ViewStorageTest.php +++ b/lib/Drupal/views/Tests/ViewStorageTest.php @@ -130,6 +130,10 @@ protected function loadTests() { // Check that all of these machine names match. $this->assertIdentical(array_keys($all_configuration_entities), array_map($prefix_map, $all_config), 'All loaded elements match.'); + + // Make sure that loaded default views get a uuid. + $view = views_get_view('frontpage'); + $this->assertTrue($view->uuid()); } /** @@ -166,6 +170,11 @@ protected function createTests() { $this->assertTrue($display instanceof ViewDisplay, format_string('Display @display is an instance of ViewDisplay.', array('@display' => $key))); } + // Check the uuid of the loaded View. + $created->set('name', 'glossary_new'); + $created->save(); + $created_loaded = $this->loadView('glossary_new'); + $this->assertIdentical($created->uuid(), $created_loaded->uuid(), 'The created uuid has been saved correctly.'); } /** diff --git a/lib/Drupal/views/ViewStorageController.php b/lib/Drupal/views/ViewStorageController.php index 5bdd1f8acb476ff73710a47e1e5172b78235402e..2bdb3a8ca4fe8ec86fa814e63ff48e36c14901df 100644 --- a/lib/Drupal/views/ViewStorageController.php +++ b/lib/Drupal/views/ViewStorageController.php @@ -9,17 +9,33 @@ use Drupal\config\ConfigStorageController; use Drupal\entity\EntityInterface; +use Drupal\Component\Uuid\Uuid; /** * Defines the storage controller class for ViewStorage entities. */ class ViewStorageController extends ConfigStorageController { + /** + * Holds a UUID factory instance. + * + * @var Drupal\Component\Uuid\Uuid + */ + protected $uuidFactory = NULL; + /** * Overrides Drupal\config\ConfigStorageController::attachLoad(); */ protected function attachLoad(&$queried_entities, $revision_id = FALSE) { foreach ($queried_entities as $id => $entity) { + // Create a uuid if we don't have one. + if (empty($entity->{$this->uuidKey})) { + // Only get an instance of uuid once. + if (!isset($this->uuidFactory)) { + $this->uuidFactory = new Uuid(); + } + $entity->{$this->uuidKey} = $this->uuidFactory->generate(); + } // @todo This property is left in for CTools export UI. $entity->type = t('Normal'); $this->attachDisplays($entity); @@ -65,6 +81,7 @@ public function save(EntityInterface $entity) { 'human_name', 'core', 'display', + 'uuid', ); foreach ($config_properties as $property) {