function text_field in Content Construction Kit (CCK) 6
Same name in this branch
- 6 examples/simple_field.php \text_field()
- 6 examples/example_field.php \text_field()
- 6 modules/text/text.module \text_field()
Same name and namespace in other branches
- 5 text.module \text_field()
- 6.3 modules/text/text.module \text_field()
- 6.2 modules/text/text.module \text_field()
Implementation of hook_field().
File
- modules/
text/ text.module, line 140 - Defines simple text field types.
Code
function text_field($op, &$node, $field, &$items, $teaser, $page) {
switch ($op) {
case 'validate':
$allowed_values = content_allowed_values($field);
if (is_array($items)) {
foreach ($items as $delta => $item) {
$error_field = $field['field_name'] . '][' . $delta . '][value';
if (!empty($item['value'])) {
if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
form_set_error($error_field, t('Illegal value for %name.', array(
'%name' => t($field['widget']['label']),
)));
}
}
}
}
if (!empty($field['max_length'])) {
foreach ($items as $delta => $data) {
$error_field = $field['field_name'] . '][' . $delta . '][value';
if (strlen($data['value']) > $field['max_length']) {
form_set_error($error_field, t('%label is longer than %max characters.', array(
'%label' => $field['widget']['label'],
'%max' => $field['max_length'],
)));
}
}
}
break;
case 'sanitize':
foreach ($items as $delta => $item) {
if (!empty($field['text_processing'])) {
$text = check_markup($item['value'], $item['format'], is_null($node) || $node->build_mode == NODE_BUILD_PREVIEW);
}
else {
$text = check_plain($item['value']);
}
$items[$delta]['safe'] = $text;
}
}
}