It is missing the documentation of hook_schema_alter() on drupal/contributions/docs/developer/hooks/core.php. This hook is implemented on drupal_get_schema().

CommentFileSizeAuthor
#3 hook_schema_alter-docs.patch1.2 KBlyricnz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TapocoL’s picture

Well, I was working on a module to add fields and to adjust the schema for the 'contact' table in core. So, when I found this hook without documentation, I thought I would just post the little piece of code I used for the hook.

/**
 * Implementation of hook_schema_alter().
 */
function mymodule_schema_alter(&$schema) {
  if (isset($schema['contact'])) {
    $schema['contact']['fields']['address'] = array(
      'type' => 'varchar',
      'length' => 256,
      'not null' => TRUE,
      'default' => '',
    );
    $schema['contact']['fields']['phone'] = array(
      'type' => 'varchar',
      'length' => 32,
      'not null' => TRUE,
      'default' => '',
    );
    $schema['contact']['fields']['fax'] = array(
      'type' => 'varchar',
      'length' => 32,
      'not null' => TRUE,
      'default' => '',
    );
  }
}

But, since this hook does NOT add the fields into the database, I will also post the rest of my code in the .install file if you are interested.

/**
 * Implementation of hook_install().
 */
function mymodule_install() {
  $ret = array();
  $schema['contact'] = array();
  mymodule_schema_alter($schema);
  foreach ($schema['contact']['fields'] as $name => $spec) {
    db_add_field($ret, 'contact', $name, $spec);
  }
}

/**
 * Implementation of hook_uninstall().
 */
function mymodule_uninstall() {
  $ret = array();
  $schema['contact'] = array();
  mymodule_schema_alter($schema);
  foreach ($schema['contact']['fields'] as $name => $spec) {
    db_drop_field($ret, 'contact', $name);
  }
}

All of this code added fields to the 'contact' db table, and the fields will be added to the 'contact' schema as well. I do not know who handles documentation, but hopefully this helps that effort.

Barry Madore’s picture

Project: Documentation » Drupal core
Version: » 7.x-dev
Component: Documentation in CVS » documentation

Moving

lyricnz’s picture

See attached patch (should be okay for drupal 6+7).

lyricnz’s picture

Status: Active » Needs review

CNR

webchick’s picture

Status: Needs review » Reviewed & tested by the community

Great. :)

lyricnz’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.