You are here

function schema_describe in Schema 6

Same name and namespace in other branches
  1. 5 schema.module \schema_describe()
  2. 7 schema.pages.inc \schema_describe()

"Describe" menu callback.

1 string reference to 'schema_describe'
schema_menu in ./schema.module
Implementation of hook_menu(). Define menu items and page callbacks. admin/build/schema calls local task(default): schema_report() admin/build/schema/report calls local task: schema_report() admin/build/schema/describe calls local task:…

File

./schema.module, line 618
The Schema module provides functionality built on the Schema API.

Code

function schema_describe() {
  $schema = drupal_get_schema(NULL, TRUE);
  ksort($schema);
  $row_hdrs = array(
    t('Name'),
    t('Type[:Size]'),
    t('Null?'),
    t('Default'),
  );
  $output = <<<EOT
<p>This page describes the Drupal database schema.  Click on a table name
to see that table's description and fields.  Table names within a table or
field description are hyperlinks to that table's description.</p>
EOT;
  $default_table_description = t('TODO: please describe this table!');
  $default_field_description = t('TODO: please describe this field!');
  foreach ($schema as $t_name => $t_spec) {
    $rows = array();
    foreach ($t_spec['fields'] as $c_name => $c_spec) {
      $row = array();
      $row[] = $c_name;
      $type = $c_spec['type'];
      if (!empty($c_spec['length'])) {
        $type .= '(' . $c_spec['length'] . ')';
      }
      if (!empty($c_spec['scale']) && !empty($c_spec['precision'])) {
        $type .= '(' . $c_spec['precision'] . ', ' . $c_spec['scale'] . ')';
      }
      if (!empty($c_spec['size']) && $c_spec['size'] != 'normal') {
        $type .= ':' . $c_spec['size'];
      }
      if ($c_spec['type'] == 'int' && !empty($c_spec['unsigned'])) {
        $type .= ', unsigned';
      }
      $row[] = $type;
      $row[] = !empty($c_spec['not null']) ? 'NO' : 'YES';
      $row[] = isset($c_spec['default']) ? is_string($c_spec['default']) ? '\'' . $c_spec['default'] . '\'' : $c_spec['default'] : '';
      $rows[] = $row;
      if (!empty($c_spec['description']) && $c_spec['description'] != $default_field_description) {
        $desc = _schema_process_description($c_spec['description']);
        $rows[] = array(
          array(
            'colspan' => count($row_hdrs),
            'data' => $desc,
          ),
        );
      }
      else {
        drupal_set_message(_schema_process_description(t('Field {!table}.@field has no description.', array(
          '!table' => $t_name,
          '@field' => $c_name,
        ))), 'warning');
      }
    }
    if (empty($t_spec['description']) || $t_spec['description'] == $default_table_description) {
      drupal_set_message(_schema_process_description(t('Table {!table} has no description.', array(
        '!table' => $t_name,
      ))), 'warning');
    }
    $form = array();
    $form[$t_name] = array(
      '#type' => 'fieldset',
      '#title' => t('@table (@module module)', array(
        '@table' => $t_name,
        '@module' => isset($t_spec['module']) ? $t_spec['module'] : '',
      )),
      '#description' => !empty($t_spec['description']) ? _schema_process_description($t_spec['description']) : '',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#attributes' => array(
        'id' => 'table-' . $t_name,
      ),
    );
    $form[$t_name]['content'] = array(
      '#value' => theme('table', $row_hdrs, $rows),
    );
    $output .= drupal_render($form);
  }
  return $output;
}