diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 1e17e66..40da4b8 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -332,19 +332,7 @@ public function bundle() { * {inheritdoc} */ public function uuid() { - $uuid = $this->getEntityKey('uuid'); - if (empty($uuid) && $this->getEntityType()->hasKey('uuid')) { - // Generate a UUID. - $uuid_service = \Drupal::service('uuid'); - $uuid = $uuid_service->generate(); - - // Set the value. - $this->set($this->getEntityType()->getKey('uuid'), $uuid); - - // Update the ::getEntityKey() static cache. - $this->entityKeys['uuid'] = $uuid; - } - return $uuid; + return $this->getEntityKey('uuid'); } /** diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php index b058439..84d1ec5 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php @@ -37,23 +37,9 @@ public static function defaultStorageSettings() { * {@inheritdoc} */ public function applyDefaultValue($notify = TRUE) { - // Default to one field item without a generated UUID. Actually generate a - // UUID in ::preSave(). - $this->setValue(array('value' => ''), $notify); - return $this; - } - - /** - * {@inheritdoc} - */ - public function preSave() { - parent::preSave(); - - if ($this->value === '') { - $uuid = \Drupal::service('uuid'); - $this->value = $uuid->generate(); - } - + // Default to one field item with a generated UUID. + $uuid = \Drupal::service('uuid'); + $this->setValue(array('value' => $uuid->generate()), $notify); return $this; } diff --git a/core/modules/rest/src/Tests/CreateTest.php b/core/modules/rest/src/Tests/CreateTest.php index 4cf60bf..d125f1b 100644 --- a/core/modules/rest/src/Tests/CreateTest.php +++ b/core/modules/rest/src/Tests/CreateTest.php @@ -116,8 +116,6 @@ public function testCreateEntityTest() { // Populate some entity properties before create the entity. $entity_values = $this->entityValues($entity_type); $entity = EntityTest::create($entity_values); - // Make sure we get a uuid. - $entity->get('uuid')->get(0)->preSave(); // Serialize the entity before the POST request. $serialized = $this->serializer->serialize($entity, $this->defaultFormat, ['account' => $account]); @@ -196,7 +194,6 @@ public function testCreateNode() { unset($entity->changed); unset($entity->revision_timestamp); } - $entity->get('uuid')->get(0)->preSave(); $serialized = $this->serializer->serialize($entity, $this->defaultFormat, ['account' => $account]); @@ -248,7 +245,6 @@ public function testCreateUser() { // Changed field can never be added. unset($entity->changed); - $entity->get('uuid')->get(0)->preSave(); $serialized = $this->serializer->serialize($entity, $this->defaultFormat, ['account' => $account]); diff --git a/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php b/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php index a419660..e8453ff 100644 --- a/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php @@ -17,8 +17,17 @@ */ class EntityFieldDefaultValueTest extends EntityUnitTestBase { + /** + * The UUID object to be used for generating UUIDs. + * + * @var \Drupal\Component\Uuid\UuidInterface + */ + protected $uuid; + protected function setUp() { parent::setUp(); + // Initiate the generator object. + $this->uuid = $this->container->get('uuid'); } /** @@ -42,6 +51,7 @@ protected function assertDefaultValues($entity_type_id) { $definition = $this->entityManager->getDefinition($entity_type_id); $langcode_key = $definition->getKey('langcode'); $this->assertEqual($entity->{$langcode_key}->value, 'en', SafeMarkup::format('%entity_type: Default language', array('%entity_type' => $entity_type_id))); + $this->assertTrue(Uuid::isValid($entity->uuid->value), SafeMarkup::format('%entity_type: Default UUID', array('%entity_type' => $entity_type_id))); $this->assertEqual($entity->name->getValue(), array(), 'Field has one empty value by default.'); } diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php index 9a4f4d4..ba3fb5b 100644 --- a/core/modules/user/src/Tests/UserRegistrationTest.php +++ b/core/modules/user/src/Tests/UserRegistrationTest.php @@ -158,21 +158,30 @@ public function testUUIDFormState() { // without administrator approval. $this->config('user.settings') ->set('verify_mail', FALSE) - ->set('register', USER_REGISTER_VISITORS) + ->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) + ->save(); + + $this->config('system.performance') + ->set('cache.page.use_internal', TRUE) + ->set('cache.page.max_age', 600) ->save(); $edit = array(); $edit['name'] = $this->randomMachineName(); $edit['mail'] = $edit['name'] . '@example.com'; + $edit['pass[pass1]'] = $edit['pass[pass2]'] = $this->randomString(8); // Create one account. $this->drupalPostForm('user/register', $edit, t('Create new account')); $this->assertResponse(200); + $this->assertText('Thank you for applying for an account'); // Create a second account. $edit['name'] = $this->randomMachineName(); $edit['mail'] = $edit['name'] . '@example.com'; - $this->drupalPostForm('user/register', $edit, t('Create new account')); + $this->drupalGet('user/register'); + $this->drupalPostForm(NULL, $edit, t('Create new account')); $this->assertResponse(200); + $this->assertText('Thank you for applying for an account'); } function testRegistrationDefaultValues() {