field_ui_field_overview_form
- Versions
- 7
field_ui_field_overview_form($form, &$form_state, $obj_type, $bundle)
Menu callback; listing of fields for a content type.
Allows fields and pseudo-fields to be re-ordered.
Code
modules/field_ui/field_ui.admin.inc, line 69
<?php
function field_ui_field_overview_form($form, &$form_state, $obj_type, $bundle) {
$bundle = field_extract_bundle($obj_type, $bundle);
field_ui_inactive_message($obj_type, $bundle);
$admin_path = _field_ui_bundle_admin_path($obj_type, $bundle);
// When displaying the form, make sure the list of fields is up-to-date.
if (empty($form_state['post'])) {
field_info_cache_clear();
}
// Gather bundle information.
$instances = field_info_instances($obj_type, $bundle);
$field_types = field_info_field_types();
$widget_types = field_info_widget_types();
$extra = field_extra_fields($bundle);
// Store each default weight so that we can add the 'add new' rows after them.
$weights = array();
$form += array(
'#tree' => TRUE,
'#object_type' => $obj_type,
'#bundle' => $bundle,
'#fields' => array_keys($instances),
'#extra' => array_keys($extra),
'#field_rows' => array(),
);
// Fields.
foreach ($instances as $name => $instance) {
$field = field_info_field($instance['field_name']);
$admin_field_path = $admin_path . '/fields/' . $instance['field_name'];
$weight = $instance['widget']['weight'];
$form[$name] = array(
'label' => array(
'#markup' => check_plain($instance['label']),
),
'field_name' => array(
'#markup' => $instance['field_name'],
),
'type' => array(
'#type' => 'link',
'#title' => t($field_types[$field['type']]['label']),
'#href' => $admin_field_path . '/field-settings',
'#options' => array('attributes' => array('title' => t('Edit field settings.'))),
),
'widget_type' => array(
'#type' => 'link',
'#title' => t($widget_types[$instance['widget']['type']]['label']),
'#href' => $admin_field_path . '/widget-type',
'#options' => array('attributes' => array('title' => t('Change widget type.'))),
),
'edit' => array(
'#type' => 'link',
'#title' => t('edit'),
'#href' => $admin_field_path,
'#options' => array('attributes' => array('title' => t('Edit instance settings.'))),
),
'delete' => array(
'#type' => 'link',
'#title' => t('delete'),
'#href' => $admin_field_path . '/delete',
'#options' => array('attributes' => array('title' => t('Delete instance.'))),
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $instance['field_name'],
),
'#row_type' => 'field',
);
if (!empty($instance['locked'])) {
$form[$name]['edit'] = array('#value' => t('Locked'));
$form[$name]['delete'] = array();
$form[$name]['#disabled_row'] = TRUE;
}
$form['#field_rows'][] = $name;
$weights[] = $weight;
}
// Non-field elements.
foreach ($extra as $name => $label) {
$weight = $extra[$name]['weight'];
$form[$name] = array(
'label' => array(
'#markup' => t($extra[$name]['label']),
),
'name' => array(
'#markup' => $name,
),
'description' => array(
'#markup' => isset($extra[$name]['description']) ? $extra[$name]['description'] : '',
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'edit' => array(
'#markup' => isset($extra[$name]['edit']) ? $extra[$name]['edit'] : '',
),
'delete' => array(
'#markup' => isset($extra[$name]['delete']) ? $extra[$name]['delete'] : '',
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $name,
),
'#disabled_row' => TRUE,
'#row_type' => 'extra',
);
$form['#field_rows'][] = $name;
$weights[] = $weight;
}
// Additional row: add new field.
$weight = !empty($weights) ? max($weights) + 1 : 0;
$field_type_options = field_ui_field_type_options();
$widget_type_options = field_ui_widget_type_options(NULL, TRUE);
if ($field_type_options && $widget_type_options) {
array_unshift($field_type_options, t('- Select a field type -'));
array_unshift($widget_type_options, t('- Select a widget -'));
$name = '_add_new_field';
$form[$name] = array(
'label' => array(
'#type' => 'textfield',
'#size' => 15,
'#description' => t('Label'),
),
'field_name' => array(
'#type' => 'textfield',
// This field should stay LTR even for RTL languages.
'#field_prefix' => '<span dir="ltr">field_',
'#field_suffix' => '</span>‎',
'#attributes' => array('dir'=>'ltr'),
'#size' => 15,
'#description' => t('Field name (a-z, 0-9, _)'),
),
'type' => array(
'#type' => 'select',
'#options' => $field_type_options,
'#description' => t('Type of data to store.'),
),
'widget_type' => array(
'#type' => 'select',
'#options' => $widget_type_options,
'#description' => t('Form element to edit the data.'),
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $name,
),
'#add_new' => TRUE,
'#row_type' => 'add_new_field',
);
$form['#field_rows'][] = $name;
}
// Additional row: add existing field.
$existing_field_options = field_ui_existing_field_options($obj_type, $bundle);
if ($existing_field_options && $widget_type_options) {
$weight++;
array_unshift($existing_field_options, t('- Select an existing field -'));
$name = '_add_existing_field';
$form[$name] = array(
'label' => array(
'#type' => 'textfield',
'#size' => 15,
'#description' => t('Label'),
),
'field_name' => array(
'#type' => 'select',
'#options' => $existing_field_options,
'#description' => t('Field to share'),
),
'widget_type' => array(
'#type' => 'select',
'#options' => $widget_type_options,
'#description' => t('Form element to edit the data.'),
),
'weight' => array(
'#type' => 'textfield',
'#default_value' => $weight,
'#size' => 3,
),
'hidden_name' => array(
'#type' => 'hidden',
'#default_value' => $name,
),
'#add_new' => TRUE,
'#row_type' => 'add_existing_field',
);
$form['#field_rows'][] = $name;
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
?>Login or register to post comments 