addSharedTableFieldIndex example

/** * {@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);

    if (\Drupal::state()->get('entity_test_update.additional_field_index.' . $table_name . '.' . $storage_definition->getName())) {
      $this->addSharedTableFieldIndex($storage_definition$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 == '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;
      }
    }

    if ($table_name == 'node_field_data') {
      switch ($field_name) {
        case 'promote':
        
      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().           $schema['fields'][$field_name]['not null'] = TRUE;
          break;

        case 'name':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;
      }
    }

    return $schema;
  }

  /** * {@inheritdoc} */
  protected function getDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, ContentEntityTypeInterface $entity_type = NULL) {
    
case 'entity_type':
        case 'field_name':
          assert($storage_definition instanceof RequiredFieldStorageDefinitionInterface);
          if ($storage_definition->isStorageRequired()) {
            // The 'entity_type' and 'field_name' are required so they also need             // to be marked as NOT NULL.             $schema['fields'][$field_name]['not null'] = TRUE;
          }
          break;

        case 'created':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;

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

    return $schema;
  }

}

  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;
      }
    }
    // Entity keys automatically have not null assigned to TRUE, but for the     // file entity, NULL is a valid value for uid.     if ($field_name === 'uid') {
      $schema['fields']['uid']['not null'] = FALSE;
    }

    return $schema;
  }

}
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;
          break;

        case 'mail':
          $this->addSharedTableFieldIndex($storage_definition$schema);
          break;

        case 'access':
        case 'created':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;
      }
    }

    return $schema;
  }

}
Home | Imprint | This part of the site doesn't use cookies.