You are here

function data_ui_edit_form in Data 7

Same name and namespace in other branches
  1. 6 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
Implements hook_menu().

File

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

Code

function data_ui_edit_form($form, &$form_state, $table) {
  $table = data_get_table($table);
  drupal_set_title($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(
        '#markup' => check_plain($field_name),
      );
      $form['fields'][$field_name]['label'] = array(
        '#type' => 'textfield',
        '#size' => 20,
        '#default_value' => isset($meta['fields'][$field_name]['label']) ? $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/structure/data/edit/' . $table
        ->get('name') . '/join/' . $field_name);
      $form['fields'][$field_name]['join']['#markup'] = $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('- Select operation -'),
    'delete' => t('Delete all selected'),
  );
  $form['bulk_operation'] = array(
    '#type' => 'select',
    '#options' => $options,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}