--- /var/www/sugargoss/modules/maxlength/maxlength.module 2009-06-07 01:53:32.000000000 +0800 +++ /var/www/sugargoss/sites/all/modules/maxlength/maxlength.module 2009-09-09 17:14:34.000000000 +0800 @@ -33,13 +33,23 @@ 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_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,7 +93,7 @@ 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) { @@ -89,7 +103,7 @@ $form['submission'][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, ); @@ -173,6 +187,7 @@ * 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 +230,7 @@ $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 +297,4 @@ } } +