diff -u b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php --- b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -105,11 +105,11 @@ protected $entityManager; /** - * The entity schema handler. + * The entity type's storage schema object. * * @var \Drupal\Core\Entity\Schema\EntityStorageSchemaInterface */ - protected $schemaHandler; + protected $storageSchema; /** * Cache backend. @@ -233,17 +233,17 @@ } /** - * Gets the schema handler for this entity storage. + * Returns the entity type's storage schema object. * * @return \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema - * The schema handler. + * The schema object. */ - protected function schemaHandler() { - if (!isset($this->schemaHandler)) { - $schema_handler_class = $this->entityType->getHandlerClass('storage_schema') ?: 'Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema'; - $this->schemaHandler = new $schema_handler_class($this->entityManager, $this->entityType, $this, $this->database); + protected function getStorageSchema() { + if (!isset($this->storageSchema)) { + $class = $this->entityType->getHandlerClass('storage_schema') ?: 'Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema'; + $this->storageSchema = new $class($this->entityManager, $this->entityType, $this, $this->database); } - return $this->schemaHandler; + return $this->storageSchema; } /** @@ -273,9 +273,8 @@ // If we are using our internal storage definitions, which is our main use // case, we can statically cache the computed table mapping. If a new set - // of field storage definitions is passed,for instance when comparing old - // and new storage schema, we just compute the table mapping but skip any - // caching. + // of field storage definitions is passed, for instance when comparing old + // and new storage schema, we compute the table mapping without caching. // @todo Clean-up this in https://www.drupal.org/node/2274017 so we can // easily instantiate a new table mapping whenever needed. if (!isset($this->tableMapping) || $storage_definitions) { @@ -1420,35 +1419,35 @@ * {@inheritdoc} */ public function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) { - return $this->schemaHandler()->requiresEntityStorageSchemaChanges($entity_type, $original); + return $this->getStorageSchema()->requiresEntityStorageSchemaChanges($entity_type, $original); } /** * {@inheritdoc} */ public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - return $this->schemaHandler()->requiresFieldStorageSchemaChanges($storage_definition, $original); + return $this->getStorageSchema()->requiresFieldStorageSchemaChanges($storage_definition, $original); } /** * {@inheritdoc} */ public function requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original) { - return $this->schemaHandler()->requiresEntityDataMigration($entity_type, $original); + return $this->getStorageSchema()->requiresEntityDataMigration($entity_type, $original); } /** * {@inheritdoc} */ public function requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - return $this->schemaHandler()->requiresFieldDataMigration($storage_definition, $original); + return $this->getStorageSchema()->requiresFieldDataMigration($storage_definition, $original); } /** * {@inheritdoc} */ public function onEntityTypeCreate(EntityTypeInterface $entity_type) { - $this->schemaHandler()->onEntityTypeCreate($entity_type); + $this->getStorageSchema()->onEntityTypeCreate($entity_type); } /** @@ -1461,14 +1460,14 @@ // definition. $this->initTableLayout(); // Let the schema handler adapt to possible table layout changes. - $this->schemaHandler()->onEntityTypeUpdate($entity_type, $original); + $this->getStorageSchema()->onEntityTypeUpdate($entity_type, $original); } /** * {@inheritdoc} */ public function onEntityTypeDelete(EntityTypeInterface $entity_type) { - $this->schemaHandler()->onEntityTypeDelete($entity_type); + $this->getStorageSchema()->onEntityTypeDelete($entity_type); } /** @@ -1483,14 +1482,14 @@ if ($this->getTableMapping()->allowsSharedTableStorage($storage_definition)) { $this->tableMapping = NULL; } - $this->schemaHandler()->onFieldStorageDefinitionCreate($storage_definition); + $this->getStorageSchema()->onFieldStorageDefinitionCreate($storage_definition); } /** * {@inheritdoc} */ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) { - $this->schemaHandler()->onFieldStorageDefinitionUpdate($storage_definition, $original); + $this->getStorageSchema()->onFieldStorageDefinitionUpdate($storage_definition, $original); } /** @@ -1514,7 +1513,7 @@ } // Update the field schema. - $this->schemaHandler()->onFieldStorageDefinitionDelete($storage_definition); + $this->getStorageSchema()->onFieldStorageDefinitionDelete($storage_definition); } /** @@ -1658,7 +1657,7 @@ * {@inheritdoc} */ public function finalizePurge(FieldStorageDefinitionInterface $storage_definition) { - $this->schemaHandler()->finalizePurge($storage_definition); + $this->getStorageSchema()->finalizePurge($storage_definition); } /** diff -u b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php --- b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -46,11 +46,11 @@ protected $storageDefinitions; /** - * The content entity schema handler used in this test. + * The storage schema handler used in this test. * * @var \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema. */ - protected $schemaHandler; + protected $storageSchema; /** * {@inheritdoc} @@ -371,7 +371,7 @@ ), ); - $this->setUpEntitySchemaHandler($expected); + $this->setUpStorageSchema($expected); $table_mapping = new DefaultTableMapping($this->storageDefinitions, $this->storageDefinitions); $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); @@ -381,7 +381,7 @@ ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->schemaHandler->onEntityTypeCreate($this->entityType); + $this->storageSchema->onEntityTypeCreate($this->entityType); } /** @@ -471,7 +471,7 @@ ), ); - $this->setUpEntitySchemaHandler($expected); + $this->setUpStorageSchema($expected); $table_mapping = new DefaultTableMapping($this->storageDefinitions, $this->storageDefinitions); $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); @@ -481,7 +481,7 @@ ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->schemaHandler->onEntityTypeCreate($this->entityType); + $this->storageSchema->onEntityTypeCreate($this->entityType); } /** @@ -561,7 +561,7 @@ ), ); - $this->setUpEntitySchemaHandler($expected); + $this->setUpStorageSchema($expected); $table_mapping = new DefaultTableMapping($this->storageDefinitions, $this->storageDefinitions); $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); @@ -571,7 +571,7 @@ ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->schemaHandler->onEntityTypeCreate($this->entityType); + $this->storageSchema->onEntityTypeCreate($this->entityType); } /** @@ -745,7 +745,7 @@ ), ); - $this->setUpEntitySchemaHandler($expected); + $this->setUpStorageSchema($expected); $table_mapping = new DefaultTableMapping($this->storageDefinitions, $this->storageDefinitions); $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions)); @@ -757,7 +757,7 @@ ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->schemaHandler->onEntityTypeCreate($this->entityType); + $this->storageSchema->onEntityTypeCreate($this->entityType); } /** @@ -962,7 +962,7 @@ ), ); - $this->setUpEntitySchemaHandler($expected); + $this->setUpStorageSchema($expected); $table_mapping = new DefaultTableMapping($this->storageDefinitions, $this->storageDefinitions); $table_mapping->setFieldNames($entity_type_id, array_keys($this->storageDefinitions)); @@ -972,11 +972,11 @@ ->method('getTableMapping') ->will($this->returnValue($table_mapping)); - $this->schemaHandler->onFieldStorageDefinitionCreate($field_storage); + $this->storageSchema->onFieldStorageDefinitionCreate($field_storage); } /** - * Sets up the schema handler. + * Sets up the storage schema object to test. * * This uses the field definitions set in $this->storageDefinitions. * @@ -984,7 +984,7 @@ * (optional) An associative array describing the expected entity schema to * be created. Defaults to expecting nothing. */ - protected function setUpEntitySchemaHandler(array $expected = array()) { + protected function setUpStorageSchema(array $expected = array()) { $this->entityManager->expects($this->any()) ->method('getDefinition') ->with($this->entityType->id()) @@ -1027,11 +1027,11 @@ ->will($this->returnValue($db_schema_handler)); $state = $this->getMock('Drupal\Core\State\StateInterface'); - $this->schemaHandler = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema') + $this->storageSchema = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema') ->setConstructorArgs(array($this->entityManager, $this->entityType, $this->storage, $connection)) ->setMethods(array('state')) ->getMock(); - $this->schemaHandler + $this->storageSchema ->expects($this->any()) ->method('state') ->will($this->returnValue($state)); diff -u b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php --- b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php @@ -338,7 +338,7 @@ $storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage') ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache)) - ->setMethods(array('schemaHandler')) + ->setMethods(array('getStorageSchema')) ->getMock(); $state = $this->getMock('Drupal\Core\State\StateInterface'); @@ -353,7 +353,7 @@ $storage ->expects($this->any()) - ->method('schemaHandler') + ->method('getStorageSchema') ->will($this->returnValue($schema_handler)); $storage->onEntityTypeCreate($this->entityType);