Project:Maxlength
Version:6.x-2.0-beta1
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work

Issue Summary

Great module, thanks.

I really like it, it works great.

How easy would it be to add a max word count? I have found that this feature is missing in Drupal and would greatly appreciate it.

peace
Jeremy

Comments

#1

Version:5.x-1.0» 6.x-2.x-dev

I'm going to try and implement this for version 6.x.

#2

Title:Max word count?» Max word count
Status:active» needs review

Attached patch adds the words count ability. Here are a few pointers:

  • After patching, go to maxlength configuration page, where you can select for each title & body field which type of limit you want it to have - character or word.
  • My patch doesn't implement a JS auto-count like in the character count.
  • I wasn't able to automatically truncate the number of words after form submission. Personally I don't like this anyhow, but if you want to try and help with this, feel free.

Please review my code.

AttachmentSize
maxlength_max_words.patch 10.78 KB

#3

Status:needs review» needs work

mh i'm not happy that you created a patch to version1, there are quite a lot of missing features in the first version.

so develop the patch against 6-2.x

so i set it to needs work

i don't like

<?php
+//      case 'prepare':
+//        // Truncate body field.
+//        $limit = intval(variable_get($code .'_b', ''));
+//        if (variable_get($code .'_bt', 'char') == 'word' && (count(explode(' ', $node->body)) > $limit)) {
+//          $type_info = node_get_types('type', $node->type);
+//         
?>

But i like the feature.

#4

It would be really great to see this feature in the future. Thanks for the work.

#5

Version:6.x-2.x-dev» 6.x-2.0-beta1
Status:needs work» needs review

This patch was not working. I got a new one coming up that implements that feature.

AttachmentSize
maxlength_wordcount.patch 9.65 KB

#6

Status:needs review» needs work

Mostly minor.

+++ sites/all/modules/maxlength/maxlength.js 2009-09-16 23:35:23.000000000 +0300
@@ -2,16 +2,33 @@
+      //alert(Drupal.t("Sorry, you reached the maximum amount of words. \n\n The last word in your text will be deleted."));

Alert is not very userfriendly. Couldn't there be a message above/below the textarea?

+++ sites/all/modules/maxlength/maxlength.js 2009-09-16 23:35:23.000000000 +0300
@@ -2,16 +2,33 @@
-
+   

MINOR: Whitespace

+++ sites/all/modules/maxlength/maxlength.module 2009-09-16 23:57:47.000000000 +0300
@@ -199,7 +232,11 @@ function _maxlength_format_element(&$ele
+      drupal_set_message("format element limit type". $values['limittype']);

Test Output? Or not translatable :)

+++ sites/all/modules/maxlength/maxlength.module 2009-09-16 23:57:47.000000000 +0300
@@ -241,12 +280,19 @@ function maxlength_nodeapi(&$node, $op,
-          if (drupal_strlen($node->$field) > $limit) {
-            form_set_error($field, t('The !field field has exceeded its maximum number of characters (!limit).', array('!limit' => $limit, '!field' => $field)));
+          if ($limittype == MAXLENGTH_LIMIT_CHARACTERS) {
+            if (drupal_strlen($node->$field) > $limit) {
+              form_set_error($field, t('The !field field has exceeded its maximum number of characters (!limit).', array('!limit' => $limit, '!field' => $field)));
+            }
+          } else {
+            if (str_word_count($node->$field) > $limit) {
+              form_set_error($field, t('The !field field has exceeded its maximum number of words (!limit).', array('!limit' => $limit, '!field' => $field)));
+            }

I would use here @ as placeholder, because it does the check_plain.

I'm on crack. Are you, too?

#7

I decided to build my own patch for this. This is my first time working with drupal, and also my first ever contribution to the open source community. Any feedback you could offer is appreciated.

The attached patch implements the following:

  • max word count
  • javascript support for displaying the remaining number of words
  • minor code fixes/cleanup
AttachmentSize
maxlength_wordcount.patch 14.88 KB

#8

+++ maxlength/maxlength.inc (revision 749)
@@ -10,3 +10,7 @@
+// Types of limits
+define('LIMIT_CHAR', 'char');
+define('LIMIT_WORD', 'word');

defines should have the modulename as prefix

+++ maxlength/maxlength.module (revision 749)
@@ -242,14 +255,18 @@
+            form_set_error($field, t('The !field field has exceeded its maximum number of words (!limit).', array('!limit' => $limit, '!field' => $field)));

@ is better than !. Yes this is a problem in the module everywhere :)

+++ maxlength/maxlength.module (revision 749)
@@ -277,8 +294,14 @@

+function _maxlength_count_words($value) {
+  if (drupal_strlen(trim($value)) == 0) {  // required as preg_split() on empty string returns 1-element array
+    return 0;
+  }

+  return count(preg_split('/\s+/', trim($value)));
+}

Comments would be cool

I'm on crack. Are you, too?

#9

In the meantime, the CCK Word Count module provides this functionality. It works for CCK Textfields and Textareas, but not for the node body.

#10

Lets focus on maxlength.

CCK Word count should join forces here
#564024: Similar module: Could this be merged into maxlength module?

In addition to Word Count modules as well
#963996: Merge into maxlength

#11

The CCK Word/Character Count module, released recently, offers this functionality.

#12

Is this feature still in discussion? In particular, for the d7 release? CCK Word/Character does not have a d7 release yet.

#13

not really sure why you wrote this comment. If noone posted something on the issue nothing happened probably.

#14

because I was curious if, somewhere that I haven't found, someone had responded to your patch, or to find out if you had given it any further thought that didn't get posted, etc. I realize it is old. would you rather I started a new comment?