You are here

function _maxlength_cck_form_alter in Maxlength 7

Same name and namespace in other branches
  1. 5.2 maxlength.module \_maxlength_cck_form_alter()
  2. 6.2 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.inc, line 84
Business logic for maxlength

Code

function _maxlength_cck_form_alter(&$form, &$form_state, $form_id) {

  //if form is being loaded, add extra config fields
  if (empty($form['#post'])) {
    $new_fields = array();
    foreach ($form['field']['settings'] as $key => $field) {
      $new_fields[$key] = $field;
      $field_key = $form['instance']['field_name']['#value'];
      if (!(strpos($field_key, 'field_') === 0)) {
        $type = isset($form['instance']['bundle']['#value']) ? $form['instance']['bundle']['#value'] : '';
        if ($type != '') {
          $field_key .= '_' . $type;
        }
      }
      if ($key == 'max_length') {
        $new_fields['maxlength_' . $form['instance']['field_name']['#value'] . '_js'] = array(
          '#type' => 'checkbox',
          '#title' => t('Enable remaining characters countdown for this field'),
          '#default_value' => variable_get('maxlength_' . $field_key . '_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_' . $form['instance']['field_name']['#value'] . '_text'] = array(
          '#type' => 'textarea',
          '#title' => t('Count down message'),
          '#default_value' => variable_get('maxlength_' . $field_key . '_text', 'Content limited to !limit characters, remaining: <strong>!remaining</strong>'),
          '#description' => t('The text used in the Javascript message under the input, where "!limit", "!remaining" and "!count" are replaced by the appropriate numbers.'),
        );
      }
    }
    $form['field']['settings'] = $new_fields;
  }
  $form['#submit'][] = '_maxlength_cck_form_submit';
}