You are here

function _maxlength_cck_form_alter in Maxlength 5.2

Same name and namespace in other branches
  1. 6.2 maxlength.inc \_maxlength_cck_form_alter()
  2. 7 maxlength.inc \_maxlength_cck_form_alter()
  3. 7.2 maxlength.inc \_maxlength_cck_form_alter()
1 call to _maxlength_cck_form_alter()
maxlength_form_alter in ./maxlength.module
Implementation of hook_form_alter().

File

./maxlength.module, line 153

Code

function _maxlength_cck_form_alter($form_id, &$form) {

  //if form is being loaded, add extra config fields
  if (empty($form['#post'])) {
    $new_fields = array();
    foreach ($form['field'] as $key => $field) {
      $new_fields[$key] = $field;
      if ($key == 'max_length') {
        $new_fields[MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] . '_js'] = array(
          '#type' => 'checkbox',
          '#title' => t('Enable remaining characters countdown for this field'),
          '#default_value' => variable_get(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] . '_js', '0'),
          '#description' => t('This will enable a Javascript based count down, as well as the client side validation for this field. If no limit set this is ignored.'),
        );
        $new_fields[MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] . '_text'] = array(
          '#type' => 'textarea',
          '#title' => t('Count down message'),
          '#default_value' => variable_get(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] . '_text', 'Content limited to !limit characters, remaining: <strong>!remaining</strong>'),
          '#description' => t('The text used in the Javascript message under the input, where "!limit" and "!remaining" are replaced by the appropriate numbers.'),
        );
      }
    }
    $form['field'] = $new_fields;
  }
  else {

    //note, max lenght for the CCK field is stored in this way as for textareas, its not in $element var passed to theme functions.
    variable_set(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'], $form['#post']['max_length']);
    variable_set(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] . '_js', $form['#post'][MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] . '_js']);
    variable_set(MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] . '_text', $form['#post'][MAXLENGTH_NODE_TYPE . $form['field_name']['#value'] . '_text']);
  }
}