function _content_admin_field in Content Construction Kit (CCK) 5
Same name and namespace in other branches
- 6 includes/content.admin.inc \_content_admin_field()
Menu callback; presents the field editing page.
6 string references to '_content_admin_field'
- content_admin_field_overview_form_submit in ./
content_admin.inc - content_copy_export in ./
content_copy.module - Process the export, get field admin forms for all requested fields and save the form values as formatted text.
- content_copy_form_alter in ./
content_copy.module - Implementation of hook_form_alter(). Intervene to run form through macro when doing export
- content_copy_import_form_submit in ./
content_copy.module - Submit handler for import form. For each submitted field: 1) add new field to the database 2) execute the imported field macro to update the settings to the imported values
- content_menu in ./
content.module - Implementation of hook_menu().
File
- ./
content_admin.inc, line 724 - Administrative interface for content type creation.
Code
function _content_admin_field($type_name, $field_name) {
$output = '';
$type = content_types($type_name);
$field = $type['fields'][$field_name];
$field_types = _content_field_types();
$field_type = $field_types[$field['type']];
$widget_types = _content_widget_types();
$widget_type = $widget_types[$field['widget']['type']];
$form = array();
$form['widget'] = array(
'#type' => 'fieldset',
'#title' => t('Widget settings'),
'#description' => t('These settings apply only to the %field field as it appears in the %type content type.', array(
'%field' => $field['widget']['label'],
'%type' => $type['name'],
)),
);
$options = array();
foreach ($widget_types as $possible_widget_name => $possible_widget_type) {
if (in_array($field['type'], $possible_widget_type['field types'])) {
$options[$possible_widget_name] = $possible_widget_type['label'];
}
}
if (count($options) == 1) {
$key = array_keys($options);
$default_widget = array_pop($key);
}
$form['widget']['widget_type'] = array(
'#type' => 'radios',
'#title' => t('Widget'),
'#options' => $options,
'#default_value' => $field['widget']['type'] ? $field['widget']['type'] : $default_widget,
'#required' => TRUE,
);
$form['widget']['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => $field['widget']['label'],
'#required' => TRUE,
);
$form['widget']['weight'] = array(
'#type' => 'hidden',
'#default_value' => $field['widget']['weight'],
);
$additions = module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']);
if (is_array($additions)) {
$form['widget'] = array_merge($form['widget'], $additions);
}
$form['widget']['description'] = array(
'#type' => 'textarea',
'#title' => t('Help text'),
'#default_value' => $field['widget']['description'],
'#rows' => 5,
'#description' => t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array(
'@tags' => _content_filter_xss_display_allowed_tags(),
)),
'#required' => FALSE,
);
// Add handling for default value if not provided by field.
if (content_handle('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) {
// Store the original default value for use in programmed forms.
// Set '#default_value' instead of '#value' so programmed values
// can override whatever we set here.
$default_value = isset($field['widget']['default_value']) ? $field['widget']['default_value'] : array();
$form['widget']['default_value'] = array(
'#type' => 'value',
'#default_value' => $default_value,
);
$form['widget']['default_value_php'] = array(
'#type' => 'value',
'#default_value' => $field['widget']['default_value_php'],
);
// We can't tell at the time we build the form if this is a programmed
// form or not, so we always end up adding the default value widget
// even if we won't use it.
$form['#attributes'] = array(
"enctype" => "multipart/form-data",
);
$form['widget']['default_value_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Default value'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$module = $widget_types[$field['widget']['type']]['module'];
$function = $module . '_widget';
if (function_exists($function)) {
$node = array();
// TODO are there things we need to add in here ?
// Make sure the default value is not a required field.
$widget_field = $field;
$widget_field['required'] = FALSE;
$function('prepare form values', $node, $widget_field, $default_value);
$form_element = $function('form', $node, $widget_field, $default_value);
}
else {
// TODO : generate a series of textfields ?
// why would a widget not have a hook_widget implementation ?
}
$form['widget']['default_value_fieldset']['default_value_widget'] = $form_element;
$form['widget']['default_value_fieldset']['default_value_widget']['#tree'] = TRUE;
$form['widget']['default_value_fieldset']['advanced_options'] = array(
'#type' => 'fieldset',
'#title' => t('PHP code'),
'#collapsible' => TRUE,
'#collapsed' => empty($field['widget']['default_value_php']),
);
if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
$db_info = content_database_info($field);
$columns = array_keys($db_info['columns']);
foreach ($columns as $key => $column) {
$columns[$key] = "'{$column}' => value for {$column}";
}
$sample = 'return array(
0 => array(' . implode(', ', $columns) . '),
// You\'ll usually want to stop here. Provide more values
// if you want your \'default value\' to be multi-valued :
1 => array(' . implode(', ', $columns) . '),
2 => ...
);';
$form['widget']['default_value_fieldset']['advanced_options']['default_value_php'] = array(
'#type' => 'textarea',
'#title' => t('Code'),
'#default_value' => isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : '',
'#rows' => 6,
'#tree' => TRUE,
'#description' => t("Advanced Usage Only: PHP code that returns a default value. Should not include <?php ?> delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format :<pre>!sample</pre>Using !link_devel 'devel load' tab on a %type content page might help you figure out the expected format.", array(
'!sample' => $sample,
'!link_devel' => l("devel.module's", 'http://www.drupal.org/project/devel'),
'%type' => $type_name,
)),
);
}
else {
$form['widget']['default_value_fieldset']['advanced_options']['markup_default_value_php'] = array(
'#type' => 'item',
'#title' => t('Code'),
'#value' => !empty($field['widget']['default_value_php']) ? '<code>' . check_plain($field['widget']['default_value_php']) . '</code>' : t('<none>'),
'#description' => empty($field['widget']['default_value_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override any value specified above.'),
);
}
}
$form['field'] = array(
'#type' => 'fieldset',
'#title' => t('Data settings'),
'#description' => t('These settings apply to the %field field in every content type in which it appears.', array(
'%field' => $field['widget']['label'],
)),
);
$form['field']['required'] = array(
'#type' => 'checkbox',
'#title' => t('Required'),
'#default_value' => $field['required'],
);
$form['field']['multiple'] = array(
'#type' => 'checkbox',
'#title' => t('Multiple values'),
'#default_value' => $field['multiple'],
);
$additions = module_invoke($field_type['module'], 'field_settings', 'form', $field);
if (is_array($additions)) {
$form['field'] = array_merge($form['field'], $additions);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save field settings'),
);
$form['type_name'] = array(
'#type' => 'value',
'#value' => $type_name,
);
$form['field_name'] = array(
'#type' => 'value',
'#value' => $field_name,
);
$form['field_type'] = array(
'#type' => 'value',
'#value' => $field['type'],
);
$form['module'] = array(
'#type' => 'value',
'#value' => implode(', ', array_unique(array(
$field_type['module'],
$widget_type['module'],
))),
);
return $form;
}