You are here

function soft_length_limit_form_node_type_form_alter in Soft Length Limit 7

Implements hook_form_FORM_ID_alter().

Adds soft length limit fields when editing a content type.

File

./soft_length_limit.module, line 55
Soft Length Limit module

Code

function soft_length_limit_form_node_type_form_alter(&$form, &$form_state, $form_id) {
  $form['submission'][SOFT_LENGTH_LIMIT_TITLE_MAX] = array(
    '#type' => 'textfield',
    '#title' => t('Soft length limit'),
    '#default_value' => variable_get(SOFT_LENGTH_LIMIT_TITLE_MAX . '_' . $form['#node_type']->type, NULL),
    '#description' => t('If any value is given here, a counter will appear next to this field, informing the user of the chosen number of allowed characters. If the number is exceeded, a warning will be shown.'),
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#weight' => -2,
  );
  $form['submission'][SOFT_LENGTH_LIMIT_TITLE_MIN] = array(
    '#type' => 'textfield',
    '#title' => t('Soft length minimum'),
    '#default_value' => variable_get(SOFT_LENGTH_LIMIT_TITLE_MIN . '_' . $form['#node_type']->type, NULL),
    '#description' => t('If any value is given here, the minimum number recommended characters will be displayed as the editor enters text in this field.'),
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
    '#weight' => -1,
  );
  $form['submission'][SOFT_LENGTH_STYLE_SELECT] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable enhanced view'),
    '#default_value' => variable_get(SOFT_LENGTH_STYLE_SELECT . '_' . $form['#node_type']->type, NULL),
    '#description' => t('Check this to enable an enhanced view of soft length states.'),
    '#weight' => -1,
  );
  $form['submission']['title_label']['#weight'] = -3;

  // Add a custom submit handler to validate that the editor didn't set the
  // maximum length to greater than 255 characters.
  $form['#validate'][] = 'soft_length_limit_validate_title_length';

  // Add a custom submit handler to save the title maximum and minimum.
  $form['#submit'][] = 'soft_length_limit_set_title_maxlength';
}