function schema_describe in Schema 5
Same name and namespace in other branches
- 6 schema.module \schema_describe()
- 7 schema.pages.inc \schema_describe()
1 string reference to 'schema_describe'
- schema_menu in ./
schema.module
File
- ./
schema.module, line 509
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;
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['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'])) {
$desc = _schema_process_description($c_spec['description']);
$rows[] = array(
array(
'colspan' => count($row_hdrs),
'data' => $desc,
),
);
}
else {
if ($t_spec['module'] != 'core') {
drupal_set_message(_schema_process_description(t('Field {!table}.@field has no description.', array(
'!table' => $t_name,
'@field' => $c_name,
))), 'error');
}
}
}
if (empty($t_spec['description']) && $t_spec['module'] != 'core') {
drupal_set_message(_schema_process_description(t('Table {!table} has no description.', array(
'!table' => $t_name,
))), 'error');
}
$form = array();
$form[$t_name] = array(
'#type' => 'fieldset',
'#title' => t('@table (@module module)', array(
'@table' => $t_name,
'@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;
}