diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 0eeadd875c..952793d30c 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -140,14 +140,33 @@ public static function createInstance(ContainerInterface $container, EntityTypeI } /** - * Gets the field storage definitions for a content entity type. + * Gets the base field definitions for a content entity type. * - * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[] - * The array of field storage definitions for the entity type, keyed by - * field name. + * @return \Drupal\Core\Field\FieldDefinitionInterface[] + * The array of base field definitions for the entity type, keyed by field + * name. + * + * @deprecated in Drupal 8.7.0 and will be removed in Drupal 9.0.0. This class + * should use the new getBaseFieldStorageDefinitions() method, all others + * should Use the getFieldStorageDefinitions method in the + * entity_field.manager service instead. + * + * @See https://www.drupal.org/node/3024926 */ public function getFieldStorageDefinitions() { - return $this->entityManager->getFieldStorageDefinitions($this->entityTypeId); + @trigger_error("SqlContentEntityStorage::getFieldStorageDefinitions is deprecated in Drupal 8.7.0 and will be removed in Drupal 9.0.0. This class should use the new getBaseFieldStorageDefinitions() method, all others should Use the getFieldStorageDefinitions method in the entity_field.manager service instead. See https://www.drupal.org/node/3024926.", E_USER_DEPRECATED); + return $this->getBaseFieldStorageDefinitions(); + } + + /** + * Gets the base field definitions for a content entity type. + * + * @return \Drupal\Core\Field\FieldDefinitionInterface[] + * The array of base field definitions for the entity type, keyed by field + * name. + */ + protected function getBaseFieldStorageDefinitions() { + return $this->entityManager->getBaseFieldDefinitions($this->entityTypeId); } /** @@ -960,10 +979,10 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam $table_mapping = $this->getTableMapping(); foreach ($table_mapping->getFieldNames($table_name) as $field_name) { - if (empty($this->getFieldStorageDefinitions()[$field_name])) { + if (empty($this->getBaseFieldStorageDefinitions()[$field_name])) { throw new EntityStorageException("Table mapping contains invalid field $field_name."); } - $definition = $this->getFieldStorageDefinitions()[$field_name]; + $definition = $this->getBaseFieldStorageDefinitions()[$field_name]; $columns = $table_mapping->getColumnNames($field_name); foreach ($columns as $column_name => $schema_name) { diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php index 50e51ad19c..f1550f245a 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -48,16 +48,6 @@ class SqlContentEntityStorageTest extends UnitTestCase { */ protected $fieldDefinitions = []; - /** - * An array of additional field storage definitions, keyed by field name. - * - * This simulates field storage definitions added through the hook - * hook_entity_field_storage_info(). - * - * @var \Drupal\Core\Field\FieldStorageDefinitionInterface[]|\PHPUnit_Framework_MockObject_MockObject[] - */ - protected $additionalFieldStorageDefinitions = []; - /** * The mocked entity manager used in this test. * @@ -1182,7 +1172,7 @@ protected function setUpEntityStorage() { $this->entityFieldManager->expects($this->any()) ->method('getFieldStorageDefinitions') - ->will($this->returnValue($this->fieldDefinitions + $this->additionalFieldStorageDefinitions)); + ->will($this->returnValue($this->fieldDefinitions)); $this->entityFieldManager->expects($this->any()) ->method('getBaseFieldDefinitions') @@ -1451,25 +1441,15 @@ public function testCleanIds() { } /** - * Tests SqlContentEntityStorage::getFieldStorageDefinitions(). - * - * @param string[] $entity_keys - * A map of entity keys to use for the mocked entity type. + * Tests that getFieldStorageDefinitions triggers a deprecation error. * - * @covers ::getFieldStorageDefinitions + * @group legacy * - * @dataProvider providerTestGetTableMappingSimple() + * @expectedDeprecation SqlContentEntityStorage::getFieldStorageDefinitions is deprecated in Drupal 8.7.0 and will be removed in Drupal 9.0.0. This class should use the new getBaseFieldStorageDefinitions() method, all others should Use the getFieldStorageDefinitions method in the entity_field.manager service instead. See https://www.drupal.org/node/3024926. */ - public function testGetFieldStorageDefinitions(array $entity_keys) { - $base_field_names = ['title', 'description', 'owner']; - $field_names = array_merge(array_values(array_filter($entity_keys)), $base_field_names); - $this->fieldDefinitions = $this->mockFieldDefinitions($field_names); - $this->additionalFieldStorageDefinitions = $this->mockFieldDefinitions(['bundle_field']); + public function testGetFieldStorageDefinitionDeprecation() { $this->setUpEntityStorage(); - - $expected = $this->fieldDefinitions + $this->additionalFieldStorageDefinitions; - $this->assertEquals($expected, $this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId)); - $this->assertEquals($expected, $this->entityStorage->getFieldStorageDefinitions()); + $this->entityStorage->getFieldStorageDefinitions(); } /**