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 = FALSE);
20 $schema['taxonomy_term_field_data']['indexes'] += [
21 'taxonomy_term__tree' => ['vid', 'weight', 'name'],
22 'taxonomy_term__vid_name' => ['vid', 'name'],
25 $schema['taxonomy_term_hierarchy'] = [
26 'description' => 'Stores the hierarchical relationship between terms.',
33 'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',
40 'description' => "Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.",
44 'parent' => ['parent'],
47 'taxonomy_term_data' => [
48 'table' => 'taxonomy_term_data',
49 'columns' => ['tid' => 'tid'],
52 'primary key' => ['tid', 'parent'],
55 $schema['taxonomy_index'] = [
56 'description' => 'Maintains denormalized information about node/term relationships.',
59 'description' => 'The {node}.nid this record tracks.',
66 'description' => 'The term ID.',
73 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
79 'description' => 'Boolean indicating whether the node is sticky.',
86 'description' => 'The Unix timestamp when the node was created.',
92 'primary key' => ['nid', 'tid'],
94 'term_node' => ['tid', 'status', 'sticky', 'created'],
99 'columns' => ['nid' => 'nid'],
102 'table' => 'taxonomy_term_data',
103 'columns' => ['tid' => 'tid'],
114 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
115 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
116 $field_name = $storage_definition->getName();
118 if ($table_name == 'taxonomy_term_field_data') {
119 // Remove unneeded indexes.
120 unset($schema['indexes']['taxonomy_term_field__vid__target_id']);
121 unset($schema['indexes']['taxonomy_term_field__description__format']);
123 switch ($field_name) {
125 // Improves the performance of the taxonomy_term__tree index defined
126 // in getEntitySchema().
127 $schema['fields'][$field_name]['not null'] = TRUE;
131 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);