You are here

function text_field in Content Construction Kit (CCK) 6.3

Same name and namespace in other branches
  1. 5 text.module \text_field()
  2. 6 examples/simple_field.php \text_field()
  3. 6 examples/example_field.php \text_field()
  4. 6 modules/text/text.module \text_field()
  5. 6.2 modules/text/text.module \text_field()

Implementation of hook_field().

File

modules/text/text.module, line 151
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_element = isset($item['_error_element']) ? $item['_error_element'] : '';
          if (is_array($item) && isset($item['_error_element'])) {
            unset($item['_error_element']);
          }
          if (!empty($item['value'])) {
            if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
              form_set_error($error_element, t('%name: illegal value.', array(
                '%name' => t($field['widget']['label']),
              )));
            }
            if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) {
              form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array(
                '%name' => $field['widget']['label'],
                '%max' => $field['max_length'],
              )));
            }
          }
        }
      }
      return $items;
    case 'sanitize':
      foreach ($items as $delta => $item) {
        if (!empty($field['text_processing'])) {
          $text = isset($item['value']) ? check_markup($item['value'], $item['format'], FALSE) : '';
        }
        else {
          $text = isset($item['value']) ? check_plain($item['value']) : '';
        }
        $items[$delta]['safe'] = $text;
      }
  }
}