You are here

protected function TermStorageSchema::getEntitySchema in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/src/TermStorageSchema.php \Drupal\taxonomy\TermStorageSchema::getEntitySchema()
  2. 9 core/modules/taxonomy/src/TermStorageSchema.php \Drupal\taxonomy\TermStorageSchema::getEntitySchema()

Gets the entity schema for the specified entity type.

Entity types may override this method in order to optimize the generated schema of the entity tables. However, only cross-field optimizations should be added here; e.g., an index spanning multiple fields. Optimizations that apply to a single field have to be added via SqlContentEntityStorageSchema::getSharedTableFieldSchema() instead.

Parameters

\Drupal\Core\Entity\ContentEntityTypeInterface $entity_type: The entity type definition.

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 value

array A Schema API array describing the entity schema, excluding dedicated field tables.

Overrides SqlContentEntityStorageSchema::getEntitySchema

File

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

Class

TermStorageSchema
Defines the term schema handler.

Namespace

Drupal\taxonomy

Code

protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
  $schema = parent::getEntitySchema($entity_type, $reset);
  if ($data_table = $this->storage
    ->getDataTable()) {
    $schema[$data_table]['indexes'] += [
      'taxonomy_term__tree' => [
        'vid',
        'weight',
        'name',
      ],
      'taxonomy_term__vid_name' => [
        'vid',
        'name',
      ],
    ];
  }
  $schema['taxonomy_index'] = [
    'description' => 'Maintains denormalized information about node/term relationships.',
    'fields' => [
      'nid' => [
        'description' => 'The {node}.nid this record tracks.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'tid' => [
        'description' => 'The term ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'status' => [
        'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ],
      'sticky' => [
        'description' => 'Boolean indicating whether the node is sticky.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
        'size' => 'tiny',
      ],
      'created' => [
        'description' => 'The Unix timestamp when the node was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'nid',
      'tid',
    ],
    'indexes' => [
      'term_node' => [
        'tid',
        'status',
        'sticky',
        'created',
      ],
    ],
    'foreign keys' => [
      'tracked_node' => [
        'table' => 'node',
        'columns' => [
          'nid' => 'nid',
        ],
      ],
      'term' => [
        'table' => 'taxonomy_term_data',
        'columns' => [
          'tid' => 'tid',
        ],
      ],
    ],
  ];
  return $schema;
}