You are here

protected function ContentModerationStateStorageSchema::getEntitySchema in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/ContentModerationStateStorageSchema.php \Drupal\content_moderation\ContentModerationStateStorageSchema::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/content_moderation/src/ContentModerationStateStorageSchema.php, line 16

Class

ContentModerationStateStorageSchema
Defines the content moderation state schema handler.

Namespace

Drupal\content_moderation

Code

protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
  $schema = parent::getEntitySchema($entity_type, $reset);

  // Creates unique keys to guarantee the integrity of the entity and to make
  // the lookup in ModerationStateFieldItemList::getModerationState() fast.
  $unique_keys = [
    'content_entity_type_id',
    'content_entity_id',
    'content_entity_revision_id',
    'workflow',
    'langcode',
  ];
  if ($data_table = $this->storage
    ->getDataTable()) {
    $schema[$data_table]['unique keys'] += [
      'content_moderation_state__lookup' => $unique_keys,
    ];
  }
  if ($revision_data_table = $this->storage
    ->getRevisionDataTable()) {
    $schema[$revision_data_table]['unique keys'] += [
      'content_moderation_state__lookup' => $unique_keys,
    ];
  }
  return $schema;
}