You are here

function data_ui_join_form in Data 6

Same name and namespace in other branches
  1. 7 data_ui/data_ui.admin.inc \data_ui_join_form()

Join form.

1 string reference to 'data_ui_join_form'
data_ui_menu in data_ui/data_ui.module
Implementation of hook_menu()

File

data_ui/data_ui.admin.inc, line 750
Admin UI functions.

Code

function data_ui_join_form(&$form_state, $table, $field_name) {

  // drupal_set_title(t('Join field'));
  $schema = $table
    ->get('table_schema');
  $meta = $table
    ->get('meta');

  // Validate input.
  if (!isset($field_name) || !isset($schema['fields'][$field_name])) {
    drupal_set_message(t('Invalid field.'), 'error');
    drupal_goto('admin/build/data/edit/' . check_url($table
      ->get('name')));
  }

  // List all tables that schema API knows about as optoins.
  // @todo: This is a looong list - needs some AHAH to scale better.
  $table_schemas = drupal_get_schema();
  ksort($table_schemas);
  $options = array();
  foreach ($table_schemas as $table_name => $schema) {
    if ($table
      ->get('name') != $table_name) {
      foreach ($schema['fields'] as $name => $info) {
        $options[$table_name][$table_name . '.' . $name] = $table_name . '.' . $name;
      }
    }
  }

  // Build form.
  $form = array();
  $form['#table'] = $table;
  $form['#field_name'] = $field_name;
  $form['#redirect'] = 'admin/build/data/edit/' . check_url($table
    ->get('name'));
  $join = _data_ui_get_join($meta['join'], $field_name);
  $form['#original_join'] = $join;
  $form['left'] = array(
    '#type' => 'select',
    '#title' => t('Join @table_field to ', array(
      '@table_field' => $table
        ->get('name') . '.' . $field_name,
    )),
    '#options' => $options,
    '#default_value' => $join['left_table'] . '.' . $join['left_field'],
  );
  $form['inner_join'] = array(
    '#type' => 'radios',
    '#title' => t('Join type'),
    '#options' => array(
      t('Left join'),
      t('Inner join'),
    ),
    '#default_value' => $join['inner_join'] ? $join['inner_join'] : 0,
  );

  // Use confirm form for its formatting.
  $form = confirm_form($form, t('Join field'), 'admin/build/data/edit/' . check_url($table
    ->get('name')), '', t('Save'), t('Cancel'));
  $form['actions']['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
    '#submit' => array(
      'data_ui_join_form_submit_delete',
    ),
  );
  krsort($form['actions']);
  return $form;
}