function update_module_enable

Helper function to install a new module in Drupal 8 via hook_update_N().

4 calls to update_module_enable()
node_update_8012 in drupal/core/modules/node/node.install
Enable History module.
toolbar_update_8001 in drupal/core/modules/toolbar/toolbar.install
Enable the Breakpoint and Config modules.
update_fix_d8_requirements in drupal/core/includes/update.inc
Perform Drupal 7.x to 8.x updates that are required for update.php to function properly.
update_prepare_d8_language in drupal/core/includes/update.inc
Prepare Drupal 8 language changes for the bootstrap if needed.

File

drupal/core/includes/update.inc, line 514
Drupal database update API.

Code

function update_module_enable(array $modules) {
  $schema_store = drupal_container()
    ->get('keyvalue')
    ->get('system.schema');
  foreach ($modules as $module) {

    // Check for initial schema and install it. The schema version of a newly
    // installed module is always 0. Using 8000 here would be inconsistent
    // since $module_update_8000() may involve a schema change, and we want
    // to install the schema as it was before any updates were added.
    $function = $module . '_schema_0';
    if (function_exists($function)) {
      $schema = $function();
      foreach ($schema as $table => $spec) {
        db_create_table($table, $spec);
      }
    }

    // Enable the module with a weight of 0.
    $module_config = config('system.module');
    $module_config
      ->set("enabled.{$module}", 0)
      ->set('enabled', module_config_sort($module_config
      ->get('enabled')))
      ->save();

    // Ensure the module is not contained in disabled modules.
    config('system.module.disabled')
      ->clear($module)
      ->save();

    // Change the schema version from SCHEMA_UNINSTALLED to 0, so any module
    // updates since the module's inception are executed in a core upgrade.
    $schema_store
      ->set($module, 0);

    // system_list_reset() is in module.inc but that would only be available
    // once the variable bootstrap is done.
    require_once DRUPAL_ROOT . '/core/includes/module.inc';
    system_list_reset();

    //  @todo: figure out what to do about hook_install() and hook_enable().
  }
}