You are here

function drupal_get_module_schema in Drupal 9

Same name and namespace in other branches
  1. 8 core/includes/schema.inc \drupal_get_module_schema()

Returns a module's schema.

This function can be used to retrieve a schema specification in hook_schema(), so it allows you to derive your tables from existing specifications.

Parameters

string $module: The module to which the table belongs.

string $table: The name of the table. If not given, the module's complete schema is returned.

Deprecated

in drupal:9.2.0 and is removed from drupal:10.0.0. No direct replacement is provided. Testing classes could use \Drupal\TestTools\Extension\SchemaInspector for introspection.

See also

https://www.drupal.org/node/2970993

\Drupal\TestTools\Extension\SchemaInspector::getTablesSpecification()

Related topics

3 calls to drupal_get_module_schema()
drupal_install_schema in core/includes/schema.inc
Creates all tables defined in a module's hook_schema().
drupal_uninstall_schema in core/includes/schema.inc
Removes all tables defined in a module's hook_schema().
SchemaDeprecationTest::testDeprecatedInstallSchema in core/tests/Drupal/KernelTests/Core/Extension/SchemaDeprecationTest.php
Tests deprecation of database schema API functions.

File

core/includes/schema.inc, line 166
Schema API handling functions.

Code

function drupal_get_module_schema($module, $table = NULL) {
  @trigger_error('drupal_get_module_schema() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. No direct replacement is provided. Testing classes could use \\Drupal\\TestTools\\Extension\\SchemaInspector for introspection. See https://www.drupal.org/node/2970993', E_USER_DEPRECATED);

  // Load the .install file to get hook_schema.
  module_load_install($module);
  $schema = \Drupal::moduleHandler()
    ->invoke($module, 'schema');
  if (isset($table)) {
    if (isset($schema[$table])) {
      return $schema[$table];
    }
    return [];
  }
  elseif (!empty($schema)) {
    return $schema;
  }
  return [];
}