function data_entity_admin_entity_type_form in Data 7
Form builder for the entity type settings.
Parameters
$table: The machine name of a table.
1 string reference to 'data_entity_admin_entity_type_form'
- data_entity_menu in data_entity/
data_entity.module - Implements hook_menu().
File
- data_entity/
data_entity.admin.inc, line 13 - Admin UI functions.
Code
function data_entity_admin_entity_type_form($form, &$form_state, $table) {
$table = data_get_table($table);
drupal_set_title($table
->get('title'));
data_entity_meta_add_defaults($table->meta);
$meta = $table
->get('meta');
$schema = $table
->get('table_schema');
$id_field_options = array();
foreach ($schema['fields'] as $field_name => $field) {
if (in_array($field['type'], array(
'serial',
'int',
))) {
$id_field_options[$field_name] = $field_name;
}
}
if (empty($id_field_options)) {
drupal_set_message(t("The table may not be declared as an entity type because it has no suitable schema field to use as an ID."), 'error');
return $form;
}
$form['#table'] = $table;
$form['is_entity_type'] = array(
'#type' => 'checkbox',
'#title' => t('Define table as an entity type'),
'#description' => t('Declare an entity type based on this table, where each row will be an entity. Requires a serial or unique integer field on the table.'),
'#default_value' => $meta['is_entity_type'],
);
$form['entity_id'] = array(
'#type' => 'radios',
'#title' => t('Entity ID field'),
'#description' => t('Select a serial or unique integer field on the table to use as the entity ID. This may not be changed once the entity type has fields.'),
'#options' => $id_field_options,
'#required' => TRUE,
'#default_value' => $meta['entity_id'],
);
// Get field instances. They will be on the bundle which has the same name
// as the entity type.
$entity_type = 'data_' . $table->name;
$instances = field_info_instances($entity_type);
if (!empty($instances[$entity_type])) {
$form['is_entity_type']['#disabled'] = TRUE;
$form['entity_id']['#disabled'] = TRUE;
drupal_set_message(t("The entity type settings may not be changed because this entity type has field instances."));
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}