You are here

function text_textfield_process in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 modules/text/text.module \text_textfield_process()
  2. 6 examples/example_field.php \text_textfield_process()
  3. 6 modules/text/text.module \text_textfield_process()

Process an individual element.

Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.

The $fields array is in $form['#field_info'][$element['#field_name']].

1 string reference to 'text_textfield_process'
text_elements in modules/text/text.module
Implementation of FAPI hook_elements().

File

modules/text/text.module, line 390
Defines simple text field types.

Code

function text_textfield_process($element, $edit, $form_state, $form) {
  $field = $form['#field_info'][$element['#field_name']];
  $field_key = $element['#columns'][0];
  $delta = $element['#delta'];
  $element[$field_key] = array(
    '#type' => 'textfield',
    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
    '#autocomplete_path' => $element['#autocomplete_path'],
    '#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60,
    '#attributes' => array(
      'class' => 'text',
    ),
    // The following values were set by the content module and need
    // to be passed down to the nested element.
    '#title' => $element['#title'],
    '#description' => $element['#description'],
    '#required' => $element['#required'],
    '#field_name' => $element['#field_name'],
    '#type_name' => $element['#type_name'],
    '#delta' => $element['#delta'],
    '#columns' => $element['#columns'],
  );
  $element[$field_key]['#maxlength'] = !empty($field['max_length']) ? $field['max_length'] : NULL;
  if (!empty($field['text_processing'])) {
    $filter_key = $element['#columns'][1];
    $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT;
    $parents = array_merge($element['#parents'], array(
      $filter_key,
    ));
    $element[$filter_key] = filter_form($format, 1, $parents);
  }

  // Used so that hook_field('validate') knows where to flag an error.
  $element['_error_element'] = array(
    '#type' => 'value',
    '#value' => implode('][', array_merge($element['#parents'], array(
      $field_key,
    ))),
  );
  return $element;
}