function ModuleInstaller::installSchema

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::installSchema()
  2. 10 core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::installSchema()
  3. 9 core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::installSchema()

Creates all tables defined in a module's hook_schema().

@internal

Parameters

string $module: The module for which the tables will be created.

1 call to ModuleInstaller::installSchema()
ModuleInstaller::doInstall in core/lib/Drupal/Core/Extension/ModuleInstaller.php
Installs a set of modules.

File

core/lib/Drupal/Core/Extension/ModuleInstaller.php, line 740

Class

ModuleInstaller
Default implementation of the module installer.

Namespace

Drupal\Core\Extension

Code

protected function installSchema(string $module) : void {
  $schemaDefinition = $this->invoke($module, 'schema') ?? [];
  $schema = $this->connection
    ->schema();
  if ($schemaDefinition instanceof Schema) {
    assert($schemaDefinition->type === SchemaDefinitionType::Module, 'Invalid schema definition type, must be SchemaDefinitionType::Module');
    assert($schemaDefinition->name === $module, 'Invalid schema definition name, must be equal to the module name');
    $schema->createSchemaFromDefinition($schemaDefinition);
  }
  else {
    foreach ($schemaDefinition as $name => $table) {
      $schema->createTable($name, $table);
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.