You are here

function _maxlength_content_type_form_alter in Maxlength 7

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

File

./maxlength.inc, line 37
Business logic for maxlength

Code

function _maxlength_content_type_form_alter(&$form, &$form_state, $form_id) {
  $type = $form['#node_type']->type;

  // If the Title Module is enabled and the Title Field is Replaced the maxlength Module
  // we don't need this functionality any more, because the title is now a field itself
  if (!module_exists('title') || title_field_replacement_enabled('node', $type, 'title') !== TRUE) {
    $labels = array(
      '-3' => 'title',
    );
    foreach ($labels as $weight => $label) {

      // bit of a hack to allow us to position the input fields correctly
      $form['submission'][$label . '_label']['#weight'] = $weight - 1;
      $form['submission']['maxlength_' . $label] = array(
        '#type' => 'fieldset',
        '#weight' => $weight,
        '#title' => t('Limit @type  length', array(
          '@type ' => $label,
        )),
        '#collapsible' => TRUE,
        '#group' => 'additional_settings',
        '#collapsed' => strlen(variable_get($type . '_' . $label, '')) == 0,
      );
      $form['submission']['maxlength_' . $label]['maxlength_' . $label] = array(
        '#type' => 'textfield',
        '#title' => t('@label max length', array(
          '@label' => ucwords($label),
        )),
        '#field_suffix' => t('characters'),
        '#return_value' => 1,
        '#size' => 4,
        '#default_value' => variable_get('maxlength_' . $label . '_' . $type, ''),
        '#description' => t('Maximum number of characters allowed for the @type field of this content type. Leave blank for an unlimited size.', array(
          '@type' => $label,
        )) . '<br/>' . '<b>' . t('Please remember, it counts all characters, including HTML, so may not work as expected with rich text editors e.g. FCKeditor / tinyMCE.') . '</b>',
      );
      $form['submission']['maxlength_' . $label]['maxlength_' . $label . '_js'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable remaining characters countdown for the @label', array(
          '@label' => ucwords($label),
        )),
        '#default_value' => variable_get('maxlength_' . $label . '_js_' . $type, '0'),
        '#description' => t('This will enable a Javascript based count down, as well as the client side validation for the @type field of this content type. If no limit set this is ignored.', array(
          '@type' => $label,
        )),
      );
      $form['submission']['maxlength_' . $label]['maxlength_' . $label . '_text'] = array(
        '#type' => 'textarea',
        '#title' => t('@label count down message', array(
          '@label' => ucwords($label),
        )),
        '#default_value' => variable_get('maxlength_' . $label . '_text_' . $type, 'Content limited to !limit characters, remaining: <strong>!remaining</strong>'),
        '#description' => t('The text used in the Javascript message under the @type input, where "@limit", "@remaining" and "@count" are replaced by the appropriate numbers.', array(
          '@type' => $label,
        )),
      );
    }
  }
}