diff --git a/core/modules/content_moderation/src/Entity/ContentModerationState.php b/core/modules/content_moderation/src/Entity/ContentModerationState.php index 4cbd96f183..5ebb93501b 100644 --- a/core/modules/content_moderation/src/Entity/ContentModerationState.php +++ b/core/modules/content_moderation/src/Entity/ContentModerationState.php @@ -152,6 +152,22 @@ public static function loadFromModeratedEntity(EntityInterface $entity) { return $content_moderation_state; } + /** + * Default value callback for the 'uid' base field definition. + * + * @see \Drupal\content_moderation\Entity\ContentModerationState::baseFieldDefinitions() + * + * @deprecated The ::getCurrentUserId method is deprecated in 8.6.x and will + * be removed before 9.0.0. + * + * @return array + * An array of default values. + */ + public static function getCurrentUserId() { + @trigger_error('The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0.', E_USER_DEPRECATED); + return [\Drupal::currentUser()->id()]; + } + /** * {@inheritdoc} */ diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index ef63472146..74916d023b 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -18,6 +18,7 @@ * Tests links between a content entity and a content_moderation_state entity. * * @group content_moderation + * @group legacy */ class ContentModerationStateTest extends KernelTestBase { @@ -613,6 +614,15 @@ public function testRevisionDefaultState($entity_type_id) { $this->assertEquals($entity->getLoadedRevisionId(), $cms_entity->get('content_entity_revision_id')->value); } + /** + * Tests the legacy method used as the default entity owner. + * + * @expectedDeprecation The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0. + */ + public function testGetCurrentUserId() { + $this->assertEquals(['0'], ContentModerationState::getCurrentUserId()); + } + /** * Creates an entity. * diff --git a/core/modules/media/src/Entity/Media.php b/core/modules/media/src/Entity/Media.php index eebeb9fad2..bcd3cfcddb 100644 --- a/core/modules/media/src/Entity/Media.php +++ b/core/modules/media/src/Entity/Media.php @@ -460,6 +460,22 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { return $fields; } + /** + * Default value callback for 'uid' base field definition. + * + * @see ::baseFieldDefinitions() + * + * @deprecated The ::getCurrentUserId method is deprecated in 8.6.x and will + * be removed before 9.0.0. + * + * @return int[] + * An array of default values. + */ + public static function getCurrentUserId() { + @trigger_error('The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0.', E_USER_DEPRECATED); + return [\Drupal::currentUser()->id()]; + } + /** * {@inheritdoc} */ diff --git a/core/modules/media/tests/src/Kernel/MediaTest.php b/core/modules/media/tests/src/Kernel/MediaTest.php index ea76a2e673..7a165de47f 100644 --- a/core/modules/media/tests/src/Kernel/MediaTest.php +++ b/core/modules/media/tests/src/Kernel/MediaTest.php @@ -8,6 +8,7 @@ * Tests Media. * * @group media + * @group legacy */ class MediaTest extends MediaKernelTestBase { @@ -34,4 +35,13 @@ public function testNameBaseField() { $this->assertEquals($field_definitions['name']->getDisplayOptions('view'), ['region' => 'hidden']); } + /** + * Tests the legacy method used as the default entity owner. + * + * @expectedDeprecation The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0. + */ + public function testGetCurrentUserId() { + $this->assertEquals(['1'], Media::getCurrentUserId()); + } + } diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index 0dfda41fb5..f41ef2c3b8 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -377,4 +377,20 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { return $fields; } + /** + * Default value callback for 'uid' base field definition. + * + * @see ::baseFieldDefinitions() + * + * @deprecated The ::getCurrentUserId method is deprecated in 8.6.x and will + * be removed before 9.0.0. + * + * @return array + * An array of default values. + */ + public static function getCurrentUserId() { + @trigger_error('The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0.', E_USER_DEPRECATED); + return [\Drupal::currentUser()->id()]; + } + } diff --git a/core/modules/node/tests/src/Kernel/NodeOwnerTest.php b/core/modules/node/tests/src/Kernel/NodeOwnerTest.php index 2ee60d0887..c1987eef70 100644 --- a/core/modules/node/tests/src/Kernel/NodeOwnerTest.php +++ b/core/modules/node/tests/src/Kernel/NodeOwnerTest.php @@ -11,6 +11,7 @@ * Tests node owner functionality. * * @group Entity + * @group legacy */ class NodeOwnerTest extends EntityKernelTestBase { @@ -70,9 +71,18 @@ public function testOwner() { // Entity::save() saves all translations! $italian->save(); - $this->assertEquals(0, $english->getOwnerId()); - $this->assertEquals(0, $german->getOwnerId()); - $this->assertEquals(0, $italian->getOwnerId()); + $this->assertEqual(0, $english->getOwnerId()); + $this->assertEqual(0, $german->getOwnerId()); + $this->assertEqual(0, $italian->getOwnerId()); + } + + /** + * Tests the legacy method used as the default entity owner. + * + * @expectedDeprecation The ::getCurrentUserId method is deprecated in 8.6.x and will be removed before 9.0.0. + */ + public function testGetCurrentUserId() { + $this->assertEquals(['0'], Node::getCurrentUserId()); } }