function drupal_get_module_schema

Same name in other branches
  1. 9 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.

Related topics

14 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().
InsertDefaultsTest::testDefaultInsert in core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php
Tests that we can run a query that uses default values for everything.
InsertDefaultsTest::testDefaultInsertWithFields in core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php
Tests that we can insert fields with values and defaults in the same query.
KernelTestBase::installSchema in core/tests/Drupal/KernelTests/KernelTestBase.php
Installs database tables from a module schema definition.

... See full list

File

core/includes/schema.inc, line 158

Code

function drupal_get_module_schema($module, $table = NULL) {
    // 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 [];
}

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