getSharedTableFieldSchema example

'user__name' => ['name', 'langcode'],
      ];
    }

    return $schema;
  }

  /** * {@inheritdoc} */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition$table_name, array $column_mapping) {
    $schema = parent::getSharedTableFieldSchema($storage_definition$table_name$column_mapping);
    $field_name = $storage_definition->getName();

    if ($table_name == 'users_field_data') {
      switch ($field_name) {
        case 'name':
          // Improves the performance of the user__name index defined           // in getEntitySchema().           $schema['fields'][$field_name]['not null'] = TRUE;
          // Make sure the field is no longer than 191 characters so we can           // add a unique constraint in MySQL.           $schema['fields'][$field_name]['length'] = UserInterface::USERNAME_MAX_LENGTH;
          
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) {
    $schema = parent::getSharedTableFieldSchema($storage_definition$table_name$column_mapping);

    if (\Drupal::state()->get('entity_test_update.additional_field_index.' . $table_name . '.' . $storage_definition->getName())) {
      $this->addSharedTableFieldIndex($storage_definition$schema);
    }

    return $schema;
  }

}
use Drupal\Core\Field\FieldStorageDefinitionInterface;

/** * Defines the menu_link_content schema handler. */
class MenuLinkContentStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition$table_name, array $column_mapping) {
    $schema = parent::getSharedTableFieldSchema($storage_definition$table_name$column_mapping);
    $field_name = $storage_definition->getName();

    if ($table_name == $this->storage->getBaseTable()) {
      switch ($field_name) {
        case 'rediscover':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;
      }
    }

    return $schema;
  }

      ];
    }

    return $schema;
  }

  /** * {@inheritdoc} */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition$table_name, array $column_mapping) {
    $schema = parent::getSharedTableFieldSchema($storage_definition$table_name$column_mapping);
    $field_name = $storage_definition->getName();

    if ($table_name == 'comment_field_data') {
      // Remove unneeded indexes.       unset($schema['indexes']['comment_field__pid__target_id']);
      unset($schema['indexes']['comment_field__entity_id__target_id']);

      switch ($field_name) {
        case 'thread':
          // Improves the performance of the comment__num_new index defined           // in getEntitySchema().
'node__title_type' => ['title', ['type', 4]],
      ];
    }

    return $schema;
  }

  /** * {@inheritdoc} */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition$table_name, array $column_mapping) {
    $schema = parent::getSharedTableFieldSchema($storage_definition$table_name$column_mapping);
    $field_name = $storage_definition->getName();

    if ($table_name == 'node_revision') {
      switch ($field_name) {
        case 'langcode':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;

        case 'revision_uid':
          $this->addSharedTableFieldForeignKey($storage_definition$schema, 'users', 'uid');
          break;
      }

      ],
    ];

    return $schema;
  }

  /** * {@inheritdoc} */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition$table_name, array $column_mapping) {
    $schema = parent::getSharedTableFieldSchema($storage_definition$table_name$column_mapping);
    $field_name = $storage_definition->getName();

    if ($table_name == 'taxonomy_term_field_data') {
      // Remove unneeded indexes.       unset($schema['indexes']['taxonomy_term_field__vid__target_id']);
      unset($schema['indexes']['taxonomy_term_field__description__format']);

      switch ($field_name) {
        case 'weight':
          // Improves the performance of the taxonomy_term__tree index defined           // in getEntitySchema().
assert(!$storage_definition->hasCustomStorage());
    $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]);
    $schema = [];
    if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) {
      $schema = $this->getDedicatedTableSchema($storage_definition);
    }
    elseif ($table_mapping->allowsSharedTableStorage($storage_definition)) {
      $field_name = $storage_definition->getName();
      foreach (array_diff($table_mapping->getTableNames()$table_mapping->getDedicatedTableNames()) as $table_name) {
        if (in_array($field_name$table_mapping->getFieldNames($table_name))) {
          $column_names = $table_mapping->getColumnNames($storage_definition->getName());
          $schema[$table_name] = $this->getSharedTableFieldSchema($storage_definition$table_name$column_names);
        }
      }
    }
    return $schema;
  }

  /** * {@inheritdoc} */
  public function requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
    // If the original storage has existing entities, or it is impossible to
use Drupal\Core\Field\FieldStorageDefinitionInterface;

/** * Defines the file schema handler. */
class FileStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@inheritdoc} */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition$table_name, array $column_mapping) {
    $schema = parent::getSharedTableFieldSchema($storage_definition$table_name$column_mapping);
    $field_name = $storage_definition->getName();

    if ($table_name == $this->storage->getBaseTable()) {
      switch ($field_name) {
        case 'status':
        case 'changed':
        case 'uri':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;
      }
    }
    
Home | Imprint | This part of the site doesn't use cookies.