3 namespace Drupal\taxonomy;
5 use Drupal\Core\Entity\ContentEntityTypeInterface;
6 use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
10 * Defines the term schema handler.
12 class TermStorageSchema extends SqlContentEntityStorageSchema {
17 protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
18 $schema = parent::getEntitySchema($entity_type, $reset);
20 if ($data_table = $this->storage->getDataTable()) {
21 $schema[$data_table]['indexes'] += [
22 'taxonomy_term__tree' => ['vid', 'weight', 'name'],
23 'taxonomy_term__vid_name' => ['vid', 'name'],
27 $schema['taxonomy_index'] = [
28 'description' => 'Maintains denormalized information about node/term relationships.',
31 'description' => 'The {node}.nid this record tracks.',
38 'description' => 'The term ID.',
45 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
51 'description' => 'Boolean indicating whether the node is sticky.',
58 'description' => 'The Unix timestamp when the node was created.',
64 'primary key' => ['nid', 'tid'],
66 'term_node' => ['tid', 'status', 'sticky', 'created'],
71 'columns' => ['nid' => 'nid'],
74 'table' => 'taxonomy_term_data',
75 'columns' => ['tid' => 'tid'],
86 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
87 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
88 $field_name = $storage_definition->getName();
90 if ($table_name == 'taxonomy_term_field_data') {
91 // Remove unneeded indexes.
92 unset($schema['indexes']['taxonomy_term_field__vid__target_id']);
93 unset($schema['indexes']['taxonomy_term_field__description__format']);
95 switch ($field_name) {
97 // Improves the performance of the taxonomy_term__tree index defined
98 // in getEntitySchema().
99 $schema['fields'][$field_name]['not null'] = TRUE;
103 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);