You are here

function _maxlength_content_type_form_alter in Maxlength 6.2

Same name and namespace in other branches
  1. 5.2 maxlength.module \_maxlength_content_type_form_alter()
  2. 7 maxlength.inc \_maxlength_content_type_form_alter()
  3. 7.2 maxlength.inc \_maxlength_content_type_form_alter()

Editing a Content Type.

Provide the fields for the user to choose maxlength settings on: Title Body Comment Title Comment Body

1 call to _maxlength_content_type_form_alter()
maxlength_form_alter in ./maxlength.module
Implementation of hook_form_alter().

File

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

Code

function _maxlength_content_type_form_alter(&$form, &$form_state, $form_id) {
  $type = $form['#node_type']->type;
  $labels = array(
    'title' => array(
      'parent_form' => 'submission',
      'weight' => '-3',
    ),
    'body' => array(
      'parent_form' => 'submission',
      'weight' => '-1',
    ),
    'comment_subject' => array(
      'parent_form' => 'comment',
      'weight' => '-1',
    ),
    'comment_comment' => array(
      'parent_form' => 'comment',
      'weight' => '0',
    ),
  );
  foreach ($labels as $label => $options) {
    $parent_form = $options['parent_form'];
    $weight = $options['weight'];
    if ($parent_form == 'submission') {

      // Ensure that the "limit title length" / "limit body length" fieldsets we create
      // are placed directly beneath the "title field label" / "body field label" form elements.
      $form[$parent_form][$label . '_label']['#weight'] = $weight - 1;
    }
    $form[$parent_form]['maxlength_' . $label]['maxlength_' . $label] = array(
      '#type' => 'fieldset',
      '#weight' => $weight,
      '#title' => t('Limit !type  length', array(
        '!type ' => $label,
      )),
      '#title' => t('Limit !type  length', array(
        '!type ' => $label,
      )),
      '#collapsible' => TRUE,
      '#collapsed' => strlen(variable_get($type . '_' . $label, '')) == 0,
    );
    $form[$parent_form]['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, MAXLENGTH_DEFAULT_LENGTH),
      '#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[$parent_form]['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, MAXLENGTH_DEFAULT_USE_JS),
      '#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[$parent_form]['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, MAXLENGTH_DEFAULT_TEXT),
      '#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,
      )),
    );
  }
}