function TermStorageSchema::getDedicatedTableSchema

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/src/TermStorageSchema.php \Drupal\taxonomy\TermStorageSchema::getDedicatedTableSchema()
  2. 8.9.x core/modules/taxonomy/src/TermStorageSchema.php \Drupal\taxonomy\TermStorageSchema::getDedicatedTableSchema()
  3. 11.x core/modules/taxonomy/src/TermStorageSchema.php \Drupal\taxonomy\TermStorageSchema::getDedicatedTableSchema()

Gets the SQL schema for a dedicated table.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: The field storage definition.

\Drupal\Core\Entity\ContentEntityTypeInterface $entity_type: (optional) The entity type definition. Defaults to the one provided by the entity storage.

Return value

array The schema definition for the table with the following keys:

  • fields: The schema definition for the each field columns.
  • indexes: The schema definition for the indexes.
  • unique keys: The schema definition for the unique keys.
  • foreign keys: The schema definition for the foreign keys.

Overrides SqlContentEntityStorageSchema::getDedicatedTableSchema

File

core/modules/taxonomy/src/TermStorageSchema.php, line 114

Class

TermStorageSchema
Defines the term schema handler.

Namespace

Drupal\taxonomy

Code

protected function getDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, ?ContentEntityTypeInterface $entity_type = NULL) {
    $dedicated_table_schema = parent::getDedicatedTableSchema($storage_definition, $entity_type);
    // Add an index on 'bundle', 'delta' and 'parent_target_id' columns to
    // increase the performance of the query from
    // \Drupal\taxonomy\TermStorage::getVocabularyHierarchyType().
    if ($storage_definition->getName() === 'parent') {
        
        /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
        $table_mapping = $this->storage
            ->getTableMapping();
        $dedicated_table_name = $table_mapping->getDedicatedDataTableName($storage_definition);
        unset($dedicated_table_schema[$dedicated_table_name]['indexes']['bundle']);
        $dedicated_table_schema[$dedicated_table_name]['indexes']['bundle_delta_target_id'] = [
            'bundle',
            'delta',
            $table_mapping->getFieldColumnName($storage_definition, 'target_id'),
        ];
    }
    return $dedicated_table_schema;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.