getEntitySchema example

use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;

/** * Defines the content moderation state schema handler. */
class ContentModerationStateStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  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()) {
      
use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;

/** * Defines the path_alias schema handler. */
class PathAliasStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type$reset = FALSE) {
    $schema = parent::getEntitySchema($entity_type$reset);

    $schema[$this->storage->getBaseTable()]['indexes'] += [
      'path_alias__alias_langcode_id_status' => ['alias', 'langcode', 'id', 'status'],
      'path_alias__path_langcode_id_status' => ['path', 'langcode', 'id', 'status'],
    ];

    return $schema;
  }

}
use Drupal\Core\Field\FieldStorageDefinitionInterface;

/** * Defines the node schema handler. */
class NodeStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type$reset = FALSE) {
    $schema = parent::getEntitySchema($entity_type$reset);

    if ($data_table = $this->storage->getDataTable()) {
      $schema[$data_table]['indexes'] += [
        'node__frontpage' => ['promote', 'status', 'sticky', 'created'],
        'node__title_type' => ['title', ['type', 4]],
      ];
    }

    return $schema;
  }

  
use Drupal\Core\Field\RequiredFieldStorageDefinitionInterface;

/** * Defines the comment schema handler. */
class CommentStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type$reset = FALSE) {
    $schema = parent::getEntitySchema($entity_type$reset);

    if ($data_table = $this->storage->getDataTable()) {
      $schema[$data_table]['indexes'] += [
        'comment__status_pid' => ['pid', 'status'],
        'comment__num_new' => [
          'entity_id',
          'entity_type',
          'comment_type',
          'status',
          'created',
          'cid',
          

    public function getSchema(array $definitions): array
    {
        $schema = [];

        ksort($definitions);

        foreach ($definitions as $definition) {
            $entity = $definition->getEntityName();

            $entitySchema = $this->getEntitySchema($definition);

            if ($entitySchema['write-protected'] && $entitySchema['read-protected']) {
                continue;
            }

            $schema[$entity] = $entitySchema;
        }

        return $schema;
    }

    


    return $this->storage->getCustomTableMapping($entity_type$field_storage_definitions);
  }

  /** * {@inheritdoc} */
  public function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
    return $this->hasSharedTableStructureChange($entity_type$original) ||
      // Detect changes in key or index definitions.       $this->getEntitySchemaData($entity_type$this->getEntitySchema($entity_type, TRUE)) != $this->loadEntitySchemaData($original);
  }

  /** * Detects whether there is a change in the shared table structure. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The new entity type. * @param \Drupal\Core\Entity\EntityTypeInterface $original * The origin entity type. * * @return bool * Returns TRUE if either the revisionable or translatable flag changes or * a table has been renamed. */
use Drupal\Core\Field\FieldStorageDefinitionInterface;

/** * Defines the user schema handler. */
class UserStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type$reset = FALSE) {
    $schema = parent::getEntitySchema($entity_type$reset);

    if ($data_table = $this->storage->getDataTable()) {
      $schema[$data_table]['unique keys'] += [
        'user__name' => ['name', 'langcode'],
      ];
    }

    return $schema;
  }

  /** * {@inheritdoc} */
use Drupal\Core\Field\FieldStorageDefinitionInterface;

/** * Defines the entity_test_update storage_schema handler. */
class EntityTestUpdateStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type$reset = FALSE) {
    $schema = parent::getEntitySchema($entity_type$reset);

    if ($entity_type->id() == 'entity_test_update') {
      $schema[$this->storage->getBaseTable()]['indexes'] += \Drupal::state()->get('entity_test_update.additional_entity_indexes', []);
    }
    return $schema;
  }

  /** * {@inheritdoc} */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition$table_name, array $column_mapping) {
    
use Drupal\Core\Field\FieldStorageDefinitionInterface;

/** * Defines the term schema handler. */
class TermStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  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' => [
        
Home | Imprint | This part of the site doesn't use cookies.