diff --git a/core/lib/Drupal/Core/Entity/EntityFieldManager.php b/core/lib/Drupal/Core/Entity/EntityFieldManager.php index 0357e99755..5919f9f243 100644 --- a/core/lib/Drupal/Core/Entity/EntityFieldManager.php +++ b/core/lib/Drupal/Core/Entity/EntityFieldManager.php @@ -453,7 +453,16 @@ public function getFieldStorageDefinitions($entity_type_id) { } /** - * {@inheritdoc} + * Gets the active field storage definitions for a content entity type. + * + * @param string $entity_type_id + * The entity type ID. Only content entities are supported. + * + * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[] + * An array of field storage definitions that are active in the current + * request, keyed by field name. + * + * @internal */ public function getActiveFieldStorageDefinitions($entity_type_id) { if (!isset($this->activeFieldStorageDefinitions[$entity_type_id])) { diff --git a/core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php index 016fe15782..327d9e309f 100644 --- a/core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFieldManagerInterface.php @@ -61,18 +61,6 @@ public function getFieldDefinitions($entity_type_id, $bundle); */ public function getFieldStorageDefinitions($entity_type_id); - /** - * Gets the active field storage definitions for a content entity type. - * - * @param string $entity_type_id - * The entity type ID. Only content entities are supported. - * - * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[] - * An array of field storage definitions that are active in the current - * request, keyed by field name. - */ - public function getActiveFieldStorageDefinitions($entity_type_id); - /** * Gets a lightweight map of fields across bundles. * diff --git a/core/lib/Drupal/Core/Entity/EntityTypeManager.php b/core/lib/Drupal/Core/Entity/EntityTypeManager.php index fe809af41e..5544e4a43d 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeManager.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeManager.php @@ -151,7 +151,15 @@ public function getDefinition($entity_type_id, $exception_on_invalid = TRUE) { } /** - * {@inheritdoc} + * Gets the active definition for a content entity type. + * + * @param string $entity_type_id + * The entity type ID. + * + * @return \Drupal\Core\Entity\EntityTypeInterface + * The active entity type definition. + * + * @internal */ public function getActiveDefinition($entity_type_id) { if (!isset($this->activeDefinitions[$entity_type_id])) { diff --git a/core/lib/Drupal/Core/Entity/EntityTypeManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeManagerInterface.php index 5ef06443bf..4a5ec77745 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeManagerInterface.php @@ -148,15 +148,4 @@ public function getDefinition($entity_type_id, $exception_on_invalid = TRUE); */ public function getDefinitions(); - /** - * Gets the active definition for a content entity type. - * - * @param string $entity_type_id - * The entity type ID. - * - * @return \Drupal\Core\Entity\EntityTypeInterface - * The active entity type definition. - */ - public function getActiveDefinition($entity_type_id); - } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 5e3fa64289..ff3c4cd7cd 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -153,8 +153,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $container->get('language_manager'), $container->get('entity.memory_cache'), $container->get('entity_type.bundle.info'), - $container->get('entity_type.manager'), - $container->get('entity.last_installed_schema.repository') + $container->get('entity_type.manager') ); } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index f6eb340f9e..544327b539 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -118,7 +118,7 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage */ public function __construct(EntityTypeManagerInterface $entity_type_manager, ContentEntityTypeInterface $entity_type, SqlContentEntityStorage $storage, Connection $database, EntityFieldManagerInterface $entity_field_manager = NULL) { $this->entityTypeManager = $entity_type_manager; - $this->storage = $storage; + $this->storage = clone $storage; $this->database = $database; if (!$entity_field_manager) { @trigger_error('Calling SqlContentEntityStorageSchema::__construct() with the $entity_field_manager argument is supported in drupal:8.7.0 and will be required before drupal:9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); diff --git a/core/modules/jsonapi/tests/src/Functional/CommentTest.php b/core/modules/jsonapi/tests/src/Functional/CommentTest.php index 0194177633..ddb7d0b8f8 100644 --- a/core/modules/jsonapi/tests/src/Functional/CommentTest.php +++ b/core/modules/jsonapi/tests/src/Functional/CommentTest.php @@ -357,7 +357,7 @@ public function testPostIndividualSkipCommentApproval() { $response = $this->request('POST', $url, $request_options); $this->assertResourceResponse(201, FALSE, $response); $this->assertFalse(Json::decode((string) $response->getBody())['data']['attributes']['status']); - $this->assertFalse($this->entityStorage->loadUnchanged(2)->isPublished()); + $this->assertFalse($this->getEntityStorage()->loadUnchanged(2)->isPublished()); // Grant anonymous permission to skip comment approval. $this->grantPermissionsToTestedRole(['skip comment approval']); @@ -366,7 +366,7 @@ public function testPostIndividualSkipCommentApproval() { $response = $this->request('POST', $url, $request_options); $this->assertResourceResponse(201, FALSE, $response); $this->assertTrue(Json::decode((string) $response->getBody())['data']['attributes']['status']); - $this->assertTrue($this->entityStorage->loadUnchanged(3)->isPublished()); + $this->assertTrue($this->getEntityStorage()->loadUnchanged(3)->isPublished()); } /** diff --git a/core/modules/jsonapi/tests/src/Functional/FileUploadTest.php b/core/modules/jsonapi/tests/src/Functional/FileUploadTest.php index d2b638cb28..b5d37de2aa 100644 --- a/core/modules/jsonapi/tests/src/Functional/FileUploadTest.php +++ b/core/modules/jsonapi/tests/src/Functional/FileUploadTest.php @@ -133,7 +133,7 @@ public function setUp() { $this->field->save(); // Reload entity so that it has the new field. - $this->entity = $this->entityStorage->loadUnchanged($this->entity->id()); + $this->entity = $this->getEntityStorage()->loadUnchanged($this->entity->id()); $this->rebuildAll(); } diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php index f50c15804a..d03f5f0ea0 100644 --- a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php +++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php @@ -194,13 +194,6 @@ */ protected $account; - /** - * The entity storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $entityStorage; - /** * The UUID key. * @@ -247,7 +240,6 @@ public function setUp() { // Create an entity. $entity_type_manager = $this->container->get('entity_type.manager'); - $this->entityStorage = $entity_type_manager->getStorage(static::$entityTypeId); $this->uuidKey = $entity_type_manager->getDefinition(static::$entityTypeId) ->getKey('uuid'); $this->entity = $this->setUpFields($this->createEntity(), $this->account); @@ -358,11 +350,11 @@ protected function setUpFields(EntityInterface $entity, UserInterface $account) * @throws \Drupal\Core\Entity\EntityStorageException */ protected function getData() { - if ($this->entityStorage->getQuery()->count()->execute() < 2) { + if ($this->getEntityStorage()->getQuery()->count()->execute() < 2) { $this->createAnotherEntity('two'); } - $query = $this->entityStorage->getQuery()->sort($this->entity->getEntityType()->getKey('id')); - return $this->entityStorage->loadMultiple($query->execute()); + $query = $this->getEntityStorage()->getQuery()->sort($this->entity->getEntityType()->getKey('id')); + return $this->getEntityStorage()->loadMultiple($query->execute()); } /** @@ -408,7 +400,7 @@ protected function normalize(EntityInterface $entity, Url $url) { protected function createAnotherEntity($key) { $duplicate = $this->getEntityDuplicate($this->entity, $key); // Some entity types are not stored, hence they cannot be reloaded. - if (get_class($this->entityStorage) !== ContentEntityNullStorage::class) { + if (get_class($this->getEntityStorage()) !== ContentEntityNullStorage::class) { $duplicate->set('field_rest_test', 'Second collection entity'); } $duplicate->save(); @@ -1980,7 +1972,7 @@ public function testPostIndividual() { $this->assertResourceResponse(201, FALSE, $response); $this->assertFalse($response->hasHeader('X-Drupal-Cache')); // If the entity is stored, perform extra checks. - if (get_class($this->entityStorage) !== ContentEntityNullStorage::class) { + if (get_class($this->getEntityStorage()) !== ContentEntityNullStorage::class) { $created_entity = $this->entityLoadUnchanged(static::$firstCreatedEntityId); $uuid = $created_entity->uuid(); // @todo Remove line below in favor of commented line in https://www.drupal.org/project/jsonapi/issues/2878463. @@ -1989,7 +1981,7 @@ public function testPostIndividual() { assert($created_entity instanceof RevisionableInterface); $location->setOption('query', ['resourceVersion' => 'id:' . $created_entity->getRevisionId()]); } - /* $location = $this->entityStorage->load(static::$firstCreatedEntityId)->toUrl('jsonapi')->setAbsolute(TRUE)->toString(); */ + /* $location = $this->getEntityStorage()->load(static::$firstCreatedEntityId)->toUrl('jsonapi')->setAbsolute(TRUE)->toString(); */ $this->assertSame([$location->setAbsolute()->toString()], $response->getHeader('Location')); // Assert that the entity was indeed created, and that the response body @@ -2025,19 +2017,19 @@ public function testPostIndividual() { // 201 for well-formed request that creates another entity. // If the entity is stored, delete the first created entity (in case there // is a uniqueness constraint). - if (get_class($this->entityStorage) !== ContentEntityNullStorage::class) { - $this->entityStorage->load(static::$firstCreatedEntityId)->delete(); + if (get_class($this->getEntityStorage()) !== ContentEntityNullStorage::class) { + $this->getEntityStorage()->load(static::$firstCreatedEntityId)->delete(); } $response = $this->request('POST', $url, $request_options); $this->assertResourceResponse(201, FALSE, $response); $this->assertFalse($response->hasHeader('X-Drupal-Cache')); if ($this->entity->getEntityType()->getStorageClass() !== ContentEntityNullStorage::class && $this->entity->getEntityType()->hasKey('uuid')) { - $second_created_entity = $this->entityStorage->load(static::$secondCreatedEntityId); + $second_created_entity = $this->getEntityStorage()->load(static::$secondCreatedEntityId); $uuid = $second_created_entity->uuid(); // @todo Remove line below in favor of commented line in https://www.drupal.org/project/jsonapi/issues/2878463. $location = Url::fromRoute(sprintf('jsonapi.%s.individual', static::$resourceTypeName), ['entity' => $uuid]); - /* $location = $this->entityStorage->load(static::$secondCreatedEntityId)->toUrl('jsonapi')->setAbsolute(TRUE)->toString(); */ + /* $location = $this->getEntityStorage()->load(static::$secondCreatedEntityId)->toUrl('jsonapi')->setAbsolute(TRUE)->toString(); */ if (static::$resourceTypeIsVersionable) { assert($created_entity instanceof RevisionableInterface); $location->setOption('query', ['resourceVersion' => 'id:' . $second_created_entity->getRevisionId()]); @@ -2062,7 +2054,7 @@ public function testPostIndividual() { $response = $this->request('POST', $url, $request_options); $this->assertResourceResponse(201, FALSE, $response); - $entities = $this->entityStorage->loadByProperties([$this->uuidKey => $new_uuid]); + $entities = $this->getEntityStorage()->loadByProperties([$this->uuidKey => $new_uuid]); $new_entity = reset($entities); $this->assertNotNull($new_entity); $new_entity->delete(); @@ -2862,7 +2854,7 @@ public function testRevisions() { // Ensure the test entity has content_moderation fields attached to it. /* @var \Drupal\Core\Entity\FieldableEntityInterface|\Drupal\Core\Entity\TranslatableRevisionableInterface $entity */ - $entity = $this->entityStorage->load($entity->id()); + $entity = $this->getEntityStorage()->load($entity->id()); // Set the published moderation state on the test entity. $entity->set('moderation_state', 'published'); @@ -3055,10 +3047,10 @@ public function testRevisions() { foreach ($test_relationship_urls as $revision_case) { list($revision_id, $relationship_url, $related_url) = $revision_case; // Load the revision that will be requested. - $this->entityStorage->resetCache([$entity->id()]); + $this->getEntityStorage()->resetCache([$entity->id()]); $revision = is_null($revision_id) - ? $this->entityStorage->load($entity->id()) - : $this->entityStorage->loadRevision($revision_id); + ? $this->getEntityStorage()->load($entity->id()) + : $this->getEntityStorage()->loadRevision($revision_id); // Request the relationship resource without access to the relationship // field. $actual_response = $this->request('GET', $relationship_url, $request_options); @@ -3080,10 +3072,10 @@ public function testRevisions() { foreach ($test_relationship_urls as $revision_case) { list($revision_id, $relationship_url, $related_url) = $revision_case; // Load the revision that will be requested. - $this->entityStorage->resetCache([$entity->id()]); + $this->getEntityStorage()->resetCache([$entity->id()]); $revision = is_null($revision_id) - ? $this->entityStorage->load($entity->id()) - : $this->entityStorage->loadRevision($revision_id); + ? $this->getEntityStorage()->load($entity->id()) + : $this->getEntityStorage()->loadRevision($revision_id); // Request the relationship resource after granting access to the // relationship field. $actual_response = $this->request('GET', $relationship_url, $request_options); @@ -3396,8 +3388,18 @@ protected function grantIncludedPermissions(array $include_paths = []) { * @todo Remove this after https://www.drupal.org/project/drupal/issues/3038706 lands. */ protected function entityLoadUnchanged($id) { - $this->entityStorage->resetCache(); - return $this->entityStorage->loadUnchanged($id); + $this->getEntityStorage()->resetCache(); + return $this->getEntityStorage()->loadUnchanged($id); + } + + /** + * Gets the entity storage for the entity type being tested. + * + * @return \Drupal\Core\Entity\EntityStorageInterface + * An entity storage object. + */ + protected function getEntityStorage() { + return \Drupal::entityTypeManager()->getStorage(static::$entityTypeId); } } diff --git a/core/modules/jsonapi/tests/src/Functional/UserTest.php b/core/modules/jsonapi/tests/src/Functional/UserTest.php index 1a72f7f2bf..7c431cd00c 100644 --- a/core/modules/jsonapi/tests/src/Functional/UserTest.php +++ b/core/modules/jsonapi/tests/src/Functional/UserTest.php @@ -352,7 +352,7 @@ public function testPatchSecurityOtherUser() { $request_options[RequestOptions::BODY] = Json::encode($user1); $response = $this->request('PATCH', $url, $request_options); // Ensure the email address has not changed. - $this->assertEquals('admin@example.com', $this->entityStorage->loadUnchanged(1)->getEmail()); + $this->assertEquals('admin@example.com', $this->getEntityStorage()->loadUnchanged(1)->getEmail()); $this->assertResourceErrorResponse(403, 'The current user is not allowed to PATCH the selected field (uid). The entity ID cannot be changed.', $url, $response, '/data/attributes/uid'); }