You are here

function schema_describe in Schema 7

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

"Describe" menu callback.

@todo Convert this into a true page callback. Somehow fieldsets do not work without being used with drupal_get_form().

1 string reference to 'schema_describe'
schema_menu in ./schema.module
Implements hook_menu().

File

./schema.pages.inc, line 124
Page callbacks for the Schema module.

Code

function schema_describe() {
  $build = array();
  $schema = schema_get_schema();
  ksort($schema);
  $row_hdrs = array(
    t('Name'),
    t('Type[:Size]'),
    t('Null?'),
    t('Default'),
    t('Description'),
  );
  $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[] = filter_xss($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[] = filter_xss($type);
      $row[] = !empty($c_spec['not null']) ? 'NO' : 'YES';
      $row[] = filter_xss(isset($c_spec['default']) ? is_string($c_spec['default']) ? '\'' . $c_spec['default'] . '\'' : $c_spec['default'] : '');
      if (!empty($c_spec['description']) && $c_spec['description'] != $default_field_description) {
        $desc = _schema_process_description($c_spec['description']);
        $row[] = filter_xss($desc);
      }
      else {
        drupal_set_message(_schema_process_description(t('Field {@table}.@field has no description.', array(
          '@table' => $t_name,
          '@field' => $c_name,
        ))), 'warning');
        $row[] = t('Description not found.');
      }
      $rows[] = $row;
    }
    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');
    }
    $build[$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,
      ),
    );
    $build[$t_name]['content'] = array(
      '#theme' => 'table',
      '#header' => $row_hdrs,
      '#rows' => $rows,
    );
  }
  return $build;
}