function view_custom_table_add_custom_table_column_relationship_form in Views Custom Table 7
Form to add table's column relationship with drupal tables.
1 call to view_custom_table_add_custom_table_column_relationship_form()
- view_custom_table_add_custom_table_to_view_form in ./
view_custom_table.admin.inc - Form to add custom table in table information table.
File
- ./
view_custom_table.admin.inc, line 88 - File for administrative functions.
Code
function view_custom_table_add_custom_table_column_relationship_form($form, &$form_state) {
$form = array();
$table_name = $form_state['table_name'];
$all_entities = entity_get_info();
$entities[''] = t('--None--');
foreach ($all_entities as $entity_name => $all_entities_item) {
$entities[$entity_name] = $all_entities_item['label'];
}
$form['columns'] = array(
'#type' => 'fieldset',
'#title' => t('"@table" Int Type Columns', array(
'@table' => $table_name,
)),
'#tree' => TRUE,
);
$int_types = array(
'tinyint',
'smallint',
'mediumint',
'int',
'bigint',
);
$text_query = format_string('DESCRIBE { @table_name }', array(
'@table_name' => $table_name,
));
$query = db_query($text_query);
foreach ($query as $row) {
$row_type = explode('(', $row->Type);
if (in_array($row_type[0], $int_types)) {
$form['columns']['column_' . $row->Field] = array(
'#type' => 'fieldset',
'#title' => t('Relation of "@field_name" with', array(
'@field_name' => ucfirst($row->Field),
)),
'#tree' => TRUE,
'#attributes' => array(
'class' => array(
'container-inline',
),
),
);
$form['columns']['column_' . $row->Field]['entity'] = array(
'#type' => 'select',
'#title' => t('Entity'),
'#options' => $entities,
);
$form['columns']['column_' . $row->Field]['field'] = array(
'#type' => 'hidden',
'#value' => $row->Field,
);
}
}
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => array(
'view_custom_table_add_custom_table_column_relationship_form_submit',
),
);
$form['actions']['cancel'] = array(
'#type' => 'markup',
'#markup' => l(t('Cancel'), 'admin/structure/views/custom_table'),
);
return $form;
}