diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index f68a0da..a2243a8 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -242,6 +242,12 @@ protected function schemaHandler() { /** * {@inheritdoc} */ + public function customizeSchema(&$schema) { + } + + /** + * {@inheritdoc} + */ public function getTableMapping() { if (!isset($this->tableMapping)) { diff --git a/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php b/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php index 4f30d47..0ef563c 100644 --- a/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php +++ b/core/lib/Drupal/Core/Entity/Schema/ContentEntitySchemaHandler.php @@ -64,11 +64,28 @@ public function __construct(EntityManagerInterface $entity_manager, ContentEntit * {@inheritdoc} */ public function getSchema() { - // Prepare basic information about the entity type. - $tables = $this->getTables(); + return $this->getEntitySchema($this->entityType); + } - if (!isset($this->schema[$this->entityType->id()])) { + /** + * Returns the entity schema for the specified entity type. + * + * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type + * The entity type definition. + * @param bool $reset + * (optional) If set to TRUE static cache will be ignored and a new schema + * array generation will be performed. Defaults to FALSE. + * + * @return array + * A Schema API array describing the entity schema, excluding dedicated + * field tables. + */ + protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) { + $entity_type_id = $entity_type->id(); + + if (!isset($this->schema[$entity_type_id]) || $reset) { // Initialize the table schema. + $tables = $this->getTables(); $schema[$tables['base_table']] = $this->initializeBaseTable(); if (isset($tables['revision_table'])) { $schema[$tables['revision_table']] = $this->initializeRevisionTable(); @@ -108,10 +125,13 @@ public function getSchema() { $this->processRevisionDataTable($schema[$tables['revision_data_table']]); } - $this->schema[$this->entityType->id()] = $schema; + // Perform additional customizations. + $this->storage->customizeSchema($schema); + + $this->schema[$entity_type_id] = $schema; } - return $this->schema[$this->entityType->id()]; + return $this->schema[$entity_type_id]; } /** diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php b/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php index 107ed26..31fb97a 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php @@ -23,4 +23,9 @@ */ public function getTableMapping(); + /** + * @todo Document. + */ + public function customizeSchema(&$schema); + } diff --git a/core/modules/aggregator/src/FeedStorage.php b/core/modules/aggregator/src/FeedStorage.php index da784f5..ddc054a 100644 --- a/core/modules/aggregator/src/FeedStorage.php +++ b/core/modules/aggregator/src/FeedStorage.php @@ -21,9 +21,7 @@ class FeedStorage extends ContentEntityDatabaseStorage implements FeedStorageInt /** * {@inheritdoc} */ - public function getSchema() { - $schema = parent::getSchema(); - + public function customizeSchema(&$schema) { // Marking the respective fields as NOT NULL makes the indexes more // performant. $schema['aggregator_feed']['fields']['url']['not null'] = TRUE; @@ -37,8 +35,6 @@ public function getSchema() { $schema['aggregator_feed']['unique keys'] += array( 'aggregator_feed__title' => array('title'), ); - - return $schema; } /** diff --git a/core/modules/aggregator/src/ItemStorage.php b/core/modules/aggregator/src/ItemStorage.php index f2b4aa6..bd38a3a 100644 --- a/core/modules/aggregator/src/ItemStorage.php +++ b/core/modules/aggregator/src/ItemStorage.php @@ -22,9 +22,7 @@ class ItemStorage extends ContentEntityDatabaseStorage implements ItemStorageInt /** * {@inheritdoc} */ - public function getSchema() { - $schema = parent::getSchema(); - + public function customizeSchema(&$schema) { // Marking the respective fields as NOT NULL makes the indexes more // performant. $schema['aggregator_item']['fields']['timestamp']['not null'] = TRUE; @@ -38,8 +36,6 @@ public function getSchema() { 'columns' => array('fid' => 'fid'), ), ); - - return $schema; } /** diff --git a/core/modules/block_content/src/BlockContentStorage.php b/core/modules/block_content/src/BlockContentStorage.php index b98a861..8301bba 100644 --- a/core/modules/block_content/src/BlockContentStorage.php +++ b/core/modules/block_content/src/BlockContentStorage.php @@ -17,9 +17,7 @@ class BlockContentStorage extends ContentEntityDatabaseStorage { /** * {@inheritdoc} */ - public function getSchema() { - $schema = parent::getSchema(); - + public function customizeSchema(&$schema) { // Marking the respective fields as NOT NULL makes the indexes more // performant. $schema['block_content_field_data']['fields']['info']['not null'] = TRUE; @@ -27,8 +25,6 @@ public function getSchema() { $schema['block_content_field_data']['unique keys'] += array( 'block_content__info' => array('info', 'langcode'), ); - - return $schema; } } diff --git a/core/modules/comment/src/CommentStorage.php b/core/modules/comment/src/CommentStorage.php index 9639d59..3618fb8 100644 --- a/core/modules/comment/src/CommentStorage.php +++ b/core/modules/comment/src/CommentStorage.php @@ -321,9 +321,7 @@ public function loadThread(EntityInterface $entity, $field_name, $mode, $comment /** * {@inheritdoc} */ - public function getSchema() { - $schema = parent::getSchema(); - + public function customizeSchema(&$schema) { // Marking the respective fields as NOT NULL makes the indexes more // performant. $schema['comment_field_data']['fields']['created']['not null'] = TRUE; @@ -356,8 +354,6 @@ public function getSchema() { 'columns' => array('uid' => 'uid'), ), ); - - return $schema; } /** diff --git a/core/modules/file/src/FileStorage.php b/core/modules/file/src/FileStorage.php index 93dae42..8da4cbc 100644 --- a/core/modules/file/src/FileStorage.php +++ b/core/modules/file/src/FileStorage.php @@ -30,9 +30,7 @@ public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT) { /** * {@inheritdoc} */ - public function getSchema() { - $schema = parent::getSchema(); - + public function customizeSchema(&$schema) { // Marking the respective fields as NOT NULL makes the indexes more // performant. $schema['file_managed']['fields']['status']['not null'] = TRUE; @@ -48,8 +46,6 @@ public function getSchema() { $schema['file_managed']['unique keys'] += array( 'file__uri' => array('uri'), ); - - return $schema; } } diff --git a/core/modules/node/src/NodeStorage.php b/core/modules/node/src/NodeStorage.php index 86cf982..9e216a5 100644 --- a/core/modules/node/src/NodeStorage.php +++ b/core/modules/node/src/NodeStorage.php @@ -62,9 +62,7 @@ public function clearRevisionsLanguage($language) { /** * {@inheritdoc} */ - public function getSchema() { - $schema = parent::getSchema(); - + public function customizeSchema(&$schema) { // Marking the respective fields as NOT NULL makes the indexes more // performant. $schema['node_field_data']['fields']['changed']['not null'] = TRUE; @@ -101,8 +99,6 @@ public function getSchema() { 'node__default_langcode' => array('default_langcode'), 'node__langcode' => array('langcode'), ); - - return $schema; } } diff --git a/core/modules/taxonomy/src/TermStorage.php b/core/modules/taxonomy/src/TermStorage.php index 345921c..38472ba 100644 --- a/core/modules/taxonomy/src/TermStorage.php +++ b/core/modules/taxonomy/src/TermStorage.php @@ -157,9 +157,7 @@ public function resetWeights($vid) { /** * {@inheritdoc} */ - public function getSchema() { - $schema = parent::getSchema(); - + public function customizeSchema(&$schema) { // Marking the respective fields as NOT NULL makes the indexes more // performant. $schema['taxonomy_term_field_data']['fields']['weight']['not null'] = TRUE; @@ -249,8 +247,6 @@ public function getSchema() { ), ), ); - - return $schema; } /** diff --git a/core/modules/user/src/UserStorage.php b/core/modules/user/src/UserStorage.php index 65209b8..7d039c3 100644 --- a/core/modules/user/src/UserStorage.php +++ b/core/modules/user/src/UserStorage.php @@ -171,9 +171,7 @@ public function updateLastAccessTimestamp(AccountInterface $account, $timestamp) /** * {@inheritdoc} */ - public function getSchema() { - $schema = parent::getSchema(); - + public function customizeSchema(&$schema) { // The "users" table does not use serial identifiers. $schema['users']['fields']['uid']['type'] = 'int'; @@ -220,8 +218,6 @@ public function getSchema() { ), ), ); - - return $schema; } }