You are here

function data_ui_edit_form in Data 6

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

Form callback for editing a table.

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

File

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

Code

function data_ui_edit_form(&$form_state, $table) {
  drupal_set_title(check_plain($table
    ->get('title')));
  $schema = $table
    ->get('table_schema');
  $meta = $table
    ->get('meta');
  $form = array();

  // Keep table.
  $form['table'] = array(
    '#type' => 'value',
    '#value' => $table,
  );

  // Existing fields.
  $form['fields'] = array(
    '#tree' => TRUE,
  );
  if (isset($schema['fields'])) {
    foreach ($schema['fields'] as $field_name => $field) {
      $form['fields'][$field_name] = array();
      $form['fields'][$field_name]['selected'] = array(
        '#type' => 'checkbox',
      );
      $form['fields'][$field_name]['name'] = array(
        '#value' => check_plain($field_name),
      );
      $form['fields'][$field_name]['label'] = array(
        '#type' => 'textfield',
        '#size' => 20,
        '#default_value' => $meta['fields'][$field_name]['label'],
      );
      $form['fields'][$field_name]['type'] = array(
        '#type' => 'select',
        '#options' => data_get_field_types(),
        '#default_value' => $field['type'],
      );
      $form['fields'][$field_name]['size'] = array(
        '#type' => 'select',
        '#options' => data_get_field_sizes(),
        '#default_value' => isset($field['size']) ? $field['size'] : 'normal',
      );
      $form['fields'][$field_name]['unsigned'] = array(
        '#type' => 'checkbox',
        '#default_value' => isset($field['unsigned']) ? $field['unsigned'] : FALSE,
      );
      $form['fields'][$field_name]['index'] = array(
        '#type' => 'checkbox',
        '#default_value' => isset($schema['indexes'][$field_name]),
      );
      $form['fields'][$field_name]['primary'] = array(
        '#type' => 'checkbox',
        '#default_value' => isset($schema['primary key']) ? in_array($field_name, $schema['primary key']) : FALSE,
      );
      if (isset($meta['join']) && ($join = _data_ui_get_join($meta['join'], $field_name))) {
        $join = $join['left_table'] . '.' . $join['left_field'];
      }
      else {
        $join = t('<none>');
      }
      $join = l($join, 'admin/build/data/edit/' . $table
        ->get('name') . '/join/' . $field_name);
      $form['fields'][$field_name]['join']['#value'] = $join;
    }
  }

  // Add a new field.
  $form['new'] = _data_ui_field_form();
  $form['new']['primary'] = array(
    '#type' => 'markup',
    '#value' => '&nbsp;',
  );
  $form['new']['join'] = array(
    '#type' => 'markup',
    '#value' => '&nbsp;',
  );
  $form['new']['add'] = array(
    '#type' => 'submit',
    '#value' => t('Add new'),
  );

  // Bulk operations.
  $options = array(
    t('Bulk operations'),
    'delete' => t('Delete all selected'),
  );
  $form['bulk_operation'] = array(
    '#type' => 'select',
    '#options' => $options,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}