function text_field_settings in Content Construction Kit (CCK) 5
Same name and namespace in other branches
- 6.3 modules/text/text.module \text_field_settings()
- 6 examples/simple_field.php \text_field_settings()
- 6 examples/example_field.php \text_field_settings()
- 6 modules/text/text.module \text_field_settings()
- 6.2 modules/text/text.module \text_field_settings()
Implementation of hook_field_settings().
File
- ./
text.module, line 20 - Defines simple text field types.
Code
function text_field_settings($op, $field) {
switch ($op) {
case 'form':
$form = array();
$options = array(
0 => t('Plain text'),
1 => t('Filtered text (user selects input format)'),
);
$form['text_processing'] = array(
'#type' => 'radios',
'#title' => t('Text processing'),
'#default_value' => isset($field['text_processing']) ? $field['text_processing'] : 0,
'#options' => $options,
);
$form['max_length'] = array(
'#type' => 'textfield',
'#title' => t('Maximum length'),
'#default_value' => isset($field['max_length']) ? $field['max_length'] : '',
'#required' => FALSE,
'#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'),
);
$form['allowed_values'] = array(
'#type' => 'textarea',
'#title' => t('Allowed values list'),
'#default_value' => !empty($field['allowed_values']) ? $field['allowed_values'] : '',
'#required' => FALSE,
'#rows' => 10,
'#description' => t('The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and it must match the field storage type (%type). The label is optional, and the key will be used as the label if no label is specified.<br />Allowed HTML tags: @tags', array(
'%type' => $field['type'],
'@tags' => _content_filter_xss_display_allowed_tags(),
)),
);
$form['advanced_options'] = array(
'#type' => 'fieldset',
'#title' => t('PHP code'),
'#collapsible' => TRUE,
'#collapsed' => empty($field['allowed_values_php']),
);
if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
$form['advanced_options']['allowed_values_php'] = array(
'#type' => 'textarea',
'#title' => t('Code'),
'#default_value' => !empty($field['allowed_values_php']) ? $field['allowed_values_php'] : '',
'#rows' => 6,
'#description' => t('Advanced Usage Only: PHP code that returns a keyed array of allowed values. Should not include <?php ?> delimiters. If this field is filled out, the array returned by this code will override the allowed values list above.'),
);
}
else {
$form['advanced_options']['markup_allowed_values_php'] = array(
'#type' => 'item',
'#title' => t('Code'),
'#value' => !empty($field['allowed_values_php']) ? '<code>' . check_plain($field['allowed_values_php']) . '</code>' : t('<none>'),
'#description' => empty($field['allowed_values_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
);
}
return $form;
case 'save':
return array(
'text_processing',
'max_length',
'allowed_values',
'allowed_values_php',
);
case 'database columns':
$columns = array(
'value' => array(
'type' => 'varchar',
'not null' => TRUE,
'default' => "''",
'sortable' => TRUE,
),
'format' => array(
'type' => 'int',
'length' => 10,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
);
if ($field['max_length'] == 0 || $field['max_length'] > 255) {
$columns['value']['type'] = 'longtext';
}
else {
$columns['value']['length'] = $field['max_length'];
}
if ($field['text_processing'] == 0) {
unset($columns['format']);
}
return $columns;
case 'arguments':
$arguments = content_views_field_arguments($field);
$alias = "content: {$field['field_name']}";
$argument = array(
'handler' => 'text_views_argument_handler',
'option' => 'string',
'help' => t('Set the option to the number of initial characters to filter by. Leave empty for full term; use 1 for an A/B/C style glossary.'),
);
$arguments[$alias] = isset($arguments[$alias]) ? array_merge($arguments[$alias], $argument) : $argument;
return $arguments;
case 'filters':
$allowed_values = text_allowed_values($field);
if (count($allowed_values)) {
return array(
'default' => array(
'list' => $allowed_values,
'list-type' => 'list',
'operator' => 'views_handler_operator_andor',
'value-type' => 'array',
),
);
}
else {
return array(
'like' => array(
'operator' => 'views_handler_operator_like',
'handler' => 'views_handler_filter_like',
),
);
}
break;
}
}