--- maxlength.module 2009-06-06 18:53:32.000000000 +0100 +++ maxlengthNew.module 2009-11-09 11:01:18.000000000 +0000 @@ -33,13 +33,23 @@ function maxlength_help($path, $arg) { function maxlength_form_alter(&$form, &$form_state, $form_id) { // Editing the content if ($form['#id'] == 'node-form') { - _maxlength_content_form_alter($form, $form_state, $form_id); + $type = $form['type']['#value']; + _maxlength_content_form_alter($form, $form_state, $type); + } + // Editing the comment + elseif ($form['#id'] == 'comment-form') { + $node = node_load($form['nid']['#value']); + $type=$node->type; + _maxlength_content_form_alter($form, $form_state, $type); } // Editing the content type elseif ($form_id == 'node_type_form' && isset($form['identity']['type'])) { _maxlength_content_type_form_alter($form, $form_state, $form_id); } - + // Editing a Comment text field. +// elseif ($form_id['#id'] == 'node-type-form' && $form['post']['op'] != 'Save content type') { +// _maxlength_content_type_form_alter($form, $form_state, $form_id); +// } // Editing a CCK text field. elseif ($form_id == 'content_field_edit_form' AND isset($form['field']['max_length'])) { _maxlength_cck_form_alter($form, $form_state, $form_id); @@ -53,14 +63,18 @@ function maxlength_form_alter(&$form, &$ } } -function _maxlength_content_form_alter(&$form, &$form_state, $form_id) { - $type = $form['type']['#value']; +function _maxlength_content_form_alter(&$form, &$form_state, $type) { + if ($form['form_id']['#id'] =='edit-post-node-form') { // update the title as needed _maxlength_format_element($form['title'], $form['title']['#default_value'], 'title', 'title', $type); // Update the body as needed _maxlength_format_element($form['body_field']['body'], $form['body_field']['body']['#default_value'], 'body', 'body', $type); - + } + elseif ($form['form_id']['#id'] =='edit-comment-form') { + // Update the comment as needed + _maxlength_format_element($form['comment_filter']['comment'], $form['comment_filter']['comment']['#default_value'], 'comment', 'comment', $type); + } if (module_exists('content')) { // Get a list of all the CCK fields for this content type @@ -79,22 +93,23 @@ function _maxlength_content_form_alter(& function _maxlength_content_type_form_alter(&$form, &$form_state, $form_id) { $type = $form['#node_type']->type; - $labels = array('-3' => 'title', '-1 ' => 'body'); + $labels = array('-3' => 'title', '-1' => 'body', '0' => 'comment'); foreach ($labels as $weight => $label) { - + $parent_form = ($label == 'comment') ? 'comment' : 'submission'; + // bit of a hack to allow us to position the input fields correctly - $form['submission'][$label .'_label']['#weight'] = $weight - 1; + $form[$parent_form][$label .'_label']['#weight'] = $weight - 1; - $form['submission'][MAXLENGTH_NODE_TYPE . $label] = array( + $form[$parent_form][MAXLENGTH_NODE_TYPE . $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['submission'][MAXLENGTH_NODE_TYPE . $label][MAXLENGTH_NODE_TYPE . $label] = array( + $form[$parent_form][MAXLENGTH_NODE_TYPE . $label][MAXLENGTH_NODE_TYPE . $label] = array( '#type' => 'textfield', '#title' => t('!label max length', array('!label' => ucwords($label))), '#field_suffix' => t('characters'), @@ -104,13 +119,13 @@ function _maxlength_content_type_form_al '#description' => t('Maximum number of characters allowed for the !type field of this content type. Leave blank for an unlimited size.', array('!type' => $label)) .'
'. ''. t('Please remember, it counts all characters, including HTML, so may not work as expected with rich text editors e.g. FCKeditor / tinyMCE.') .'', ); - $form['submission'][MAXLENGTH_NODE_TYPE . $label][MAXLENGTH_NODE_TYPE . $label .'_js'] = array( + $form[$parent_form][MAXLENGTH_NODE_TYPE . $label][MAXLENGTH_NODE_TYPE . $label .'_js'] = array( '#type' => 'checkbox', '#title' => t('Enable remaining characters countdown for the !label', array('!label' => ucwords($label))), '#default_value' => variable_get(MAXLENGTH_NODE_TYPE . $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_NODE_TYPE . $label][MAXLENGTH_NODE_TYPE . $label .'_text'] = array( + $form[$parent_form][MAXLENGTH_NODE_TYPE . $label][MAXLENGTH_NODE_TYPE . $label .'_text'] = array( '#type' => 'textarea', '#title' => t('!label count down message', array('!label' => ucwords($label))), '#default_value' => variable_get(MAXLENGTH_NODE_TYPE . $label .'_text_'. $type, 'Content limited to !limit characters, remaining: !remaining'), @@ -173,6 +188,7 @@ function _maxlength_cck_form_submit($for * Can we use a theme function to let alter the placement of the maxlength text. */ function _maxlength_format_element(&$element, $value = '', $field, $id, $type = '') { + $values = _maxlength_get_values($field, $type); if ($values !== FALSE AND isset($values['limit']) AND $values['limit'] AND $values['use_js']) { @@ -215,7 +231,7 @@ function _maxlength_get_values($field = $values['limit'] = variable_get(MAXLENGTH_NODE_TYPE . $field, FALSE); $values['use_js'] = variable_get(MAXLENGTH_NODE_TYPE . $field .'_js', FALSE); $values['text'] = variable_get(MAXLENGTH_NODE_TYPE . $field .'_text', FALSE); - } //body and title + } //body and title and comment elseif ($type != '') { $values['limit'] = variable_get(MAXLENGTH_NODE_TYPE . $field .'_'. $type, FALSE); $values['use_js'] = variable_get(MAXLENGTH_NODE_TYPE . $field .'_js_'. $type, FALSE); @@ -282,3 +298,4 @@ function maxlength_node_type($op, $info) } } +