function content_admin_field_overview_form in Content Construction Kit (CCK) 6
Same name and namespace in other branches
- 5 content_admin.inc \content_admin_field_overview_form()
Menu callback; listing of fields for a content type.
Allows fields to be reordered and nested in fieldgroups using JS drag-n-drop. Non-CCK form elements can also be moved around.
2 string references to 'content_admin_field_overview_form'
- content_menu in ./
content.module - Implementation of hook_menu().
- fieldgroup_form_alter in modules/
fieldgroup/ fieldgroup.module
File
- includes/
content.admin.inc, line 51 - Administrative interface for content type creation.
Code
function content_admin_field_overview_form(&$form_state, $type_name) {
// When displaying the form, make sure the list of 'extra' fields
// is up-to-date.
if (empty($form_state['post'])) {
content_clear_type_cache();
}
// Gather type information.
$type = content_types($type_name);
$fields = $type['fields'];
if (empty($fields)) {
drupal_set_message(t('There are no fields configured for this content type. You can !link.', array(
'!link' => l(t('Add a new field'), str_replace('/fields', '/add_field', $_GET['q'])),
)), 'warning');
return array();
}
$extra = $type['extra'];
$groups = $group_options = array();
if (module_exists('fieldgroup')) {
$groups = fieldgroup_groups($type['type']);
$group_options = _fieldgroup_groups_label($type['type']);
}
// Rows in this table are essentially nested, but for the simplicity of
// theme and submit functions, we keep them in a flat array, and use a
// $dummy render structure to figure the right display order.
$dummy = array();
$form = array(
'#tree' => TRUE,
'#type_name' => $type['type'],
'#fields' => array_keys($fields),
'#groups' => array_keys($groups),
'#extra' => array_keys($extra),
'#order' => array(),
'#prefix' => '<p>' . t('To change the order of a field, grab a drag-and-drop handle under the Label column and drag the field to a new location in the list. (Grab a handle by clicking and holding the mouse while hovering over a handle icon.) Remember that your changes will not be saved until you click the Save button at the bottom of the page.') . '</p>',
);
// Fields.
foreach ($fields as $name => $field) {
$weight = $field['widget']['weight'];
$form[$name] = array(
'human_name' => array(
'#value' => $field['widget']['label'],
),
'name' => array(
'#value' => $field['field_name'],
),
'type' => array(
'#value' => $field['type'],
),
'configure' => array(
'#value' => l(t('Configure'), 'admin/content/node-type/' . $type['url_str'] . '/fields/' . $field['field_name'] . '/edit'),
),
'remove' => array(
'#value' => l(t('Remove'), 'admin/content/node-type/' . $type['url_str'] . '/fields/' . $field['field_name'] . '/remove'),
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
),
'parent' => array(
'#type' => 'select',
'#options' => $group_options,
'#default_value' => '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $field['field_name'],
),
'#leaf' => TRUE,
);
$dummy[$name] = array(
'#weight' => $weight,
'#value' => $name . ' ',
);
}
// Groups.
foreach ($groups as $name => $group) {
$weight = $group['weight'];
$form[$name] = array(
'human_name' => array(
'#value' => $group['label'],
),
'name' => array(
'#value' => $group['group_name'],
),
'type' => array(),
'configure' => array(
'#value' => l(t('Configure'), 'admin/content/node-type/' . $type['url_str'] . '/groups/' . $group['group_name'] . '/edit'),
),
'remove' => array(
'#value' => l(t('Remove'), 'admin/content/node-type/' . $type['url_str'] . '/groups/' . $group['group_name'] . '/remove'),
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
),
'parent' => array(
'#type' => 'hidden',
'#default_value' => '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $group['group_name'],
),
'#root' => TRUE,
);
$dummy[$name] = array(
'#weight' => $weight,
'#value' => $name . ' ',
);
// Adjust child fields rows.
foreach ($group['fields'] as $field_name => $field) {
$form[$field_name]['#depth'] = 1;
$form[$field_name]['parent']['#default_value'] = $name;
$dummy[$name][$field_name] = $dummy[$field_name];
unset($dummy[$field_name]);
}
}
// Non-CCK 'fields'.
foreach ($extra as $name => $label) {
$weight = $extra[$name]['weight'];
$form[$name] = array(
'human_name' => array(
'#value' => $extra[$name]['label'],
),
'name' => array(),
'type' => array(),
'configure' => array(),
'remove' => array(),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
),
'parent' => array(
'#type' => 'hidden',
'#default_value' => '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $name,
),
'#leaf' => TRUE,
'#root' => TRUE,
'#disabled' => TRUE,
);
$dummy[$name] = array(
'#weight' => $weight,
'#value' => $name . ' ',
);
}
// Let drupal_render figure out the right order for the rows.
$form['#order'] = explode(' ', trim(drupal_render($dummy)));
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}