You are here

function data_entity_admin_entity_form in Data 7

Form builder for table entity options.

1 string reference to 'data_entity_admin_entity_form'
data_entity_menu in data_entity/data_entity.module
Implements hook_menu().

File

data_entity/data_entity.admin.inc, line 93
Admin UI functions.

Code

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

  // Add in our defaults to the table meta data.
  data_entity_meta_add_defaults($table->meta);
  $meta = $table
    ->get('meta');
  if (empty($meta['is_entity_type'])) {
    drupal_set_message(t("This table has not been declared as an entity type."));
    return $form;
  }

  // Keep table.
  $form['table'] = array(
    '#type' => 'value',
    '#value' => $table,
  );
  $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]['name'] = array(
        '#markup' => $field_name,
      );
      $form['fields'][$field_name]['locked'] = array(
        '#type' => 'checkbox',
        '#default_value' => $meta['fields'][$field_name]['locked'],
      );
      $form['fields'][$field_name]['required'] = array(
        '#type' => 'checkbox',
        '#default_value' => $meta['fields'][$field_name]['required'],
      );
      $form['fields'][$field_name]['label_field'] = array(
        '#type' => 'radio',
        '#parents' => array(
          'label_field',
        ),
        '#return_value' => $field_name,
        '#default_value' => $field_name == $meta['label_field'] ? $field_name : '',
      );
    }
  }

  // The id field has these set automatically; it's just there for show.
  $id_field = $meta['entity_id'];
  $form['fields'][$id_field]['locked']['#default_value'] = TRUE;
  $form['fields'][$id_field]['locked']['#disabled'] = TRUE;
  $form['fields'][$id_field]['required']['#default_value'] = TRUE;
  $form['fields'][$id_field]['required']['#disabled'] = TRUE;
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}