diff --git a/core/lib/Drupal/Core/Field/BaseFieldDefinition.php b/core/lib/Drupal/Core/Field/BaseFieldDefinition.php index e3bc8cd539..2aa402ffa0 100644 --- a/core/lib/Drupal/Core/Field/BaseFieldDefinition.php +++ b/core/lib/Drupal/Core/Field/BaseFieldDefinition.php @@ -500,8 +500,6 @@ public function setDefaultValue($value) { } } $this->definition['default_value'] = $value; - // Setting a fixed value should override any default value callback. - unset($this->definition['default_value_callback']); return $this; } diff --git a/core/modules/content_moderation/tests/src/Functional/Update/ContentModerationUpdateTest.php b/core/modules/content_moderation/tests/src/Functional/Update/ContentModerationUpdateTest.php index 4c2913b2f9..13e029d987 100644 --- a/core/modules/content_moderation/tests/src/Functional/Update/ContentModerationUpdateTest.php +++ b/core/modules/content_moderation/tests/src/Functional/Update/ContentModerationUpdateTest.php @@ -18,7 +18,6 @@ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles = [ __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz', __DIR__ . '/../../../fixtures/update/drupal-8.4.0-content_moderation_installed.php', - __DIR__ . '/../../../fixtures/update/drupal-8.default-cms-entity-id-2941736.php', ]; } diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php index 62d606cbc2..c0e58e04e9 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php @@ -542,7 +542,6 @@ public function testAutocreateValidation() { $file = File::create([ 'filename' => $filename, 'status' => 0, - 'uid' => NULL, ]); $entity = EntityTest::create([ diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php index a094e3144e..6f00a2d0cc 100644 --- a/core/modules/file/src/Entity/File.php +++ b/core/modules/file/src/Entity/File.php @@ -214,9 +214,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['langcode']->setLabel(t('Language code')) ->setDescription(t('The file language code.')); - $fields['uid'] - ->setDescription(t('The user ID of the file.')) - ->setDefaultValue(0); + $fields['uid']->setDescription(t('The user ID of the file.')); $fields['filename'] = BaseFieldDefinition::create('string') ->setLabel(t('Filename')) @@ -256,4 +254,11 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { return $fields; } + /** + * {@inheritdoc} + */ + public static function getDefaultEntityOwner() { + return NULL; + } + } diff --git a/core/modules/node/tests/src/Kernel/NodeOwnerTest.php b/core/modules/node/tests/src/Kernel/NodeOwnerTest.php index c12f3115c1..2ee60d0887 100644 --- a/core/modules/node/tests/src/Kernel/NodeOwnerTest.php +++ b/core/modules/node/tests/src/Kernel/NodeOwnerTest.php @@ -70,9 +70,9 @@ public function testOwner() { // Entity::save() saves all translations! $italian->save(); - $this->assertEqual(0, $english->getOwnerId()); - $this->assertEqual(0, $german->getOwnerId()); - $this->assertEqual(0, $italian->getOwnerId()); + $this->assertEquals(0, $english->getOwnerId()); + $this->assertEquals(0, $german->getOwnerId()); + $this->assertEquals(0, $italian->getOwnerId()); } } diff --git a/core/modules/user/src/EntityOwnerTrait.php b/core/modules/user/src/EntityOwnerTrait.php index cfed188b7a..40fb0a19f5 100644 --- a/core/modules/user/src/EntityOwnerTrait.php +++ b/core/modules/user/src/EntityOwnerTrait.php @@ -37,7 +37,7 @@ public static function ownerBaseFieldDefinitions(EntityTypeInterface $entity_typ $entity_type->getKey('owner') => BaseFieldDefinition::create('entity_reference') ->setLabel(new TranslatableMarkup('User ID')) ->setSetting('target_type', 'user') - ->setDefaultValueCallback(static::class . '::getCurrentUserId'), + ->setDefaultValueCallback(static::class . '::getDefaultEntityOwner'), ]; } @@ -54,6 +54,7 @@ public function getOwnerId() { public function setOwnerId($uid) { $key = $this->getEntityType()->getKey('owner'); $this->set($key, $uid); + unset($this->translatableEntityKeys['owner']); return $this; } @@ -72,17 +73,18 @@ public function getOwner() { public function setOwner(UserInterface $account) { $key = $this->getEntityType()->getKey('owner'); $this->set($key, $account->id()); + unset($this->translatableEntityKeys['owner']); return $this; } /** - * Default value callback for 'uid' base field definition. + * Default value callback for 'owner' base field definition. * * @return array * An array of default values. */ - public static function getCurrentUserId() { + public static function getDefaultEntityOwner() { return [\Drupal::currentUser()->id()]; }