Installs a specific table from a module schema definition.
Use this to install a particular table from System module.
string $module: The name of the module that defines the table's schema.
string $table: The name of the table to install.
protected function installSchema($module, $table) {
// drupal_get_schema_unprocessed() is technically able to install a schema
// of a non-enabled module, but its ability to load the module's .install
// file depends on many other factors. To prevent differences in test
// behavior and non-reproducible test failures, we only allow the schema of
// explicitly loaded/enabled modules to be installed.
if (!module_exists($module)) {
throw new \RuntimeException(format_string("'@module' module is not enabled.", array(
'@module' => $module,
)));
}
$schema = drupal_get_schema_unprocessed($module, $table);
if (empty($schema)) {
throw new \RuntimeException(format_string("Unable to retrieve '@module' module schema for '@table' table.", array(
'@module' => $module,
'@table' => $table,
)));
}
Database::getConnection()
->schema()
->createTable($table, $schema);
// We need to refresh the schema cache, as any call to drupal_get_schema()
// would not know of/return the schema otherwise.
// @todo Refactor Schema API to make this obsolete.
drupal_get_schema(NULL, TRUE);
}