37c37,39 < _maxlength_content_form_alter($form, $form_state, $type); --- > _maxlength_format_element($form['title'], $form['title']['#default_value'], 'title', 'title', $type); > _maxlength_format_element($form['body_field']['body'], $form['body_field']['body']['#default_value'], 'body', 'body', $type); > _maxlength_format_cck_elements($form, $form_state, $type); 43c45,47 < _maxlength_content_form_alter($form, $form_state, $type); --- > // Add a max length formatter to the comment subject and body > _maxlength_format_element($form['subject'], $form['subject']['#default_value'], 'subject', 'subject', $type); > _maxlength_format_element($form['comment_filter']['comment'], $form['comment_filter']['comment']['#default_value'], 'comment', 'comment', $type); 66,78c70,73 < function _maxlength_content_form_alter(&$form, &$form_state, $type) { < if ($form['form_id']['#id'] =='edit-post-node-form') { //TODO: investigate and check why this expression is being used, rather than that in the original. < // 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') { // TODO: Add the _maxlength_format_element method to the comment subject... < // Update the comment as needed < _maxlength_format_element($form['comment_filter']['comment'], $form['comment_filter']['comment']['#default_value'], 'comment', 'comment', $type); < } < --- > function _maxlength_format_cck_elements(&$form, &$form_state, $type) { > // It has been determined that we are editing the content of a node > // add all maxlength formatters to all the cck fields > 94a90,95 > /* Editing a Content Type. Provide the fields for the user to choose maxlength settings on: > * Title > * Body > * Comment Title > * Comment Body > */ 96,99c97,107 < $labels = array('-3' => 'title', '-1' => 'body', '0' => 'comment'); < < foreach ($labels as $weight => $label) { < $parent_form = ($label == 'comment') ? 'comment' : 'submission'; --- > > $labels = array( > 'title' => array('parent_form' => 'submission', 'weight' => '-3'), > 'body' => array('parent_form' => 'submission', 'weight' => '-1'), > 'subject' => array('parent_form' => 'comment', 'weight' => '-1'), > 'comment' => array('parent_form' => 'comment', 'weight' => '0'), > ); > > foreach ($labels as $label => $options) { > $parent_form = $options['parent_form']; > $weight = $options['weight']; 101,103c109,115 < // bit of a hack to allow us to position the input fields correctly < $form[$parent_form][$label .'_label']['#weight'] = $weight - 1; < --- > if ($parent_form == 'submission') > { > // Ensure that the "limit title length" / "limit body length" fieldssets we create > // are placed directly beneath the "title field label" / "body field label" form elements > $form[$parent_form][$label .'_label']['#weight'] = $weight - 1; > } > 256a269,270 > > // TODO: add equivalent validation for when comments are submitted. They are not currently checked 272a287,318 > > function maxlength_comment(&$comment_values, $op) { > switch ($op) > { > case 'validate' : > // Raise errors if the comment subject or body exceeds their maxlength > $fields = array('subject', 'comment'); > $node = node_load($comment_values['nid']); > foreach ($fields as $field) { > $limit = intval(variable_get(MAXLENGTH_NODE_TYPE . $field .'_'. $node->type, '')); > if ($limit > 0) { > if (drupal_strlen($comment_values[$field]) > $limit) { > form_set_error($field, t('The !field field has exceeded its maximum number of characters (!limit).', array('!limit' => $limit, '!field' => $field))); > } > } > } > break; > case 'insert' : > // the auto-population of the subject line may have made it exceed the maximum length. > // If so, update the comment with a truncated subject > $node = node_load($comment_values['nid']); > $field = 'subject'; > $limit = intval(variable_get(MAXLENGTH_NODE_TYPE . $field .'_'. $node->type, '')); > if ($limit > 0) { > if (drupal_strlen($comment_values[$field]) > $limit) { > $comment_values[$field] = drupal_substr($comment_values[$field], 0, $limit); > comment_save($comment_values); > } > } > break; > } > }