A patch for add limit comment length to maxlength module.

Comments

dawehner’s picture

Cool.

+++ /var/www/sugargoss/sites/all/modules/maxlength/maxlength.module	2009-09-09 17:14:34.000000000 +0800
@@ -33,13 +33,23 @@
-
+  // 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);
+//  }

I miss settings for comments. I will test the patch tonight.

This review is powered by Dreditor.

dawehner’s picture

Status: Patch (to be ported) » Needs work

oh this should be .

nicks’s picture

Thanks for the patch. It seems to work fine. The only thing I would add is that I had expected the "comment limit length" options in the edit content type page to be in the "comment settings" form, rather than in the "submission form settings" form, which only has details for the title and body. Also, in its current location it sits between the "limit body length" and "minimum number of words" form fields. This is confusing because it makes it look as though the "minimum number of words" field applies to comments rather than the body.

nicks’s picture

StatusFileSize
new6.12 KB

I changed the position of the "comment limit length" option to the comment form. I haven't made a patch before, and I've looked at it and I'm not sure it is correct, so I'll explain here too. The change I made to dereine's version is tiny, inside the foreach of _maxlength_content_type_form_alter(), I added:

    $parent_form = ($label == 'comment') ? 'comment' : 'submission';

And I then changed the form variables from:

    $form['submission']

to:

    $form[$parent_form]
youkho’s picture

Thanks for the patch

playfulwolf’s picture

#4 works for me

mburak’s picture

are you moving this patch to 6.x-2.x HEAD?

a_c_m’s picture

#4 Patch applies cleanly and works as advertised.

However for completeness, i would like to see it applied to the subject as well as the body of the comment before committing.

a_c_m’s picture

i spoke to soon, it looks like this patch is set only to work for one content type :

+  if ($form['form_id']['#id'] =='edit-post-node-form') {

Where 'post' is the content type.

Needs work.

playfulwolf’s picture

any news about this patch?

nicks’s picture

I'm still planning to take a look at this, but I just have too much work on at the moment, I expect to look at it within 1-2 weeks, but others are welcome to jump in in the mean time.

playfulwolf’s picture

I can help as beta tester. Have a live site with this patch implemented.

dawehner’s picture

And, does the patch works fine?

playfulwolf’s picture

yes, but read all thread...

sgabe’s picture

Patch in #4 works fine for me, thank you!

nicks’s picture

StatusFileSize
new4.59 KB

Right, I have gone over the comment functionality, and created a new version of maxlength.module which corrects the multitude of errors with the version posted above. The problems were:
* No validation was provided on comment body if javascript was not used
* Maxlength could not be applied to the comment subject
* The countdowns for the node title and body no longer appeared

These are all fixed in the given patch. In making these changes, I have changed quite a bit of code, so I hope this doesn't conflict with any other changes that have been made on this code in the mean time!

Hope people find it useful,

a_c_m’s picture

Thanks Nicks, looks good from a first glance, i will see if i can make time today / tomorrow to get it committed !

mikejonesok’s picture

Exactly what I needed. Thanks!

gausarts’s picture

Subscribing. Thanks

a_c_m’s picture

@nicks - can you confirm you patched against 6.x-2.x-dev ? I just tried to apply the patch and it missed on every chunk.

nicks’s picture

Version: 6.x-2.x-dev » 6.x-2.0-beta1

Oh dear, I did the work on 6.x-2.0-beta1, so perhaps it's not so useful...!? It's the first proper patch I've submitted, so I guess that's a learning point to switch to the dev branch before you try doing anything significant...

I am pretty busy for the next couple of weeks, so won't get to look at the differences between the two versions for a while.

nicks’s picture

Version: 6.x-2.0-beta1 » 6.x-2.x-dev

Changing back to 6.x-2.x-dev - since that is where this needs to be committed

a_c_m’s picture

Not to worry, soon as you can, i will review and commit.

xplan’s picture

Version: 6.x-2.x-dev » 6.x-2.0-beta1
Category: feature » support

#16 maxlengthcomments.patch
The countdowns for comment not work

sgabe’s picture

Version: 6.x-2.0-beta1 » 6.x-2.x-dev
Category: support » feature
Status: Needs work » Needs review

Still a feature request... Changing to NR since we have a patch in #16 to try out.

Updated:

@nicks: would you provide another patch with your progress? I can't apply the one in #16, it seems to be invalid and looks kinda fuzzy...

skizzo’s picture

Subscribing. patch #16 is missing the filenames (can't find file to patch at input line 1)

nicks’s picture

StatusFileSize
new9.17 KB

Hi. Sorry for the silence. I plan to look at making a 6.x-2.x-dev patch for this now I have a bit more time. I'm not sure what happened with my previous patch, but I've at least re-created a patch for the 6.x-2.x-beta1 version. Hopefully this one will work for people!

Nick

nicks’s picture

StatusFileSize
new9.17 KB

So it looks like my changes apply to 6.x-2.x-dev without any problem at all, so here's another patch:

skizzo’s picture

patch #27 applies and works nicely on 6.x-2.0-beta1. Thank you!

gausarts’s picture

#28 failed on my latest maxlength dev. Thanks

nicks’s picture

I just tested the patch on the Jan-18-2010 version of 6.x-2.x-dev which I downloaded from the project page and it worked fine for me. Can you confirm that this is the same version you tried to apply the patch to? Or give me any other info that would help me work out why the patch is failing?

gausarts’s picture

I used wysiwyg with tinymce and garland.

The configurations appear okay in the content type page, but the counter doesn't show up in the comment form. Do you think tinymce may interfere? But I had already install the compatibility plugin for tinymce as I found here somewhere and works fine in the node form, but not comment form. The good thing is if I place a larger amount of text than the preset, they are truncated to the limit.

Still digging around though, as I applied the patch manually :)

Thanks

UPDATE: I did some tweaks to the form, my mistake, it appears now, but still frozen. Not counting yet.

gausarts’s picture

So the problem is tinymce. When I disabled the editor, the counter starts working. Any idea to fix it?

I guess this part needs more work:

    /**
     * Gets executed when a TinyMCE editor instance is initialized.
     *
     * @param {TinyMCE_Control} Initialized TinyMCE editor control instance. 
     */
    init : function(ed, url) {      
      ed.onKeyDown.addToTop(this.handler);
    },
    handler : function(e) {
      
      txt = tinyMCE.activeEditor.getContent()      
      element = e.id;
            
      for (var id in Drupal.settings.maxlength) {      
        if (id == element) {
          var limit = Drupal.settings.maxlength[id];
          // calculate the remaining count of chars
          var remainingCnt = limit - txt.length;        
          // update the remaing chars text
          $('#maxlength-'+element.substr(5) + ' span.maxlength-counter-remaining').html(remainingCnt.toString());
        }
      }
    }

Thanks

gausarts’s picture

I reported the problem in the plugin page => http://drupal.org/node/314508 to be more specific to the issue. Thanks

gausarts’s picture

Status: Needs review » Reviewed & tested by the community

UPDATE: Again this was my mistake. So sorry, hope this won't happen again. I forgot to check the compat mode with the comment filter. So both actually works from the beginning. Marking this SOLVED for my case. Hope this can be included in the next package.

Can I mark this reviewed and tested by community? This should be the very first time in my three years of membership here in drupal to do this :) But feel free to change it to something else if anyone minds.

Thanks

dawehner’s picture

Status: Reviewed & tested by the community » Needs work

Some codestyle :)

+  switch ($op)
+  {
+  foreach ($labels as $label => $options) {
+		$parent_form = $options['parent_form'];
+		$weight = $options['weight'];
+		
+    if ($parent_form == 'submission')
+    {

tabs and wrong identation.

nicks’s picture

StatusFileSize
new9.17 KB

Here's a patch with the code style updates. I couldn't see any other style issues, but that may just be because I am not completely au fait with drupal style guidelines, so feel free to point them out if I've missed any.

dawehner’s picture

Status: Needs work » Needs review

Update status

colin49’s picture

subscribe

vako’s picture

Can this be committed as an independent module? so many patches, suggestions, comments....confusion. A module or a final update will be appreciated.

a_c_m’s picture

Vako, it makes no sense as an additional module.

The patch is "needing review", please do so and confirm it works if you want to see it included in the module.

vako’s picture

StatusFileSize
new6.2 KB

oh I see, this is part of the Maxlength module. OK, I will test it.
Just for curiosity, have you seen the module Facebook Status at http://drupal.org/project/facebook_status
It has a very nice countdown option to set the limit of the text entered.

momper’s picture

subscribe

gordon’s picture

subscribe

annkie’s picture

I tried the patch in #27 but I keep getting this:
patching file maxlength.module
patch unexpectedly ends in middle of line
patch: **** malformed patch at line 189:

What am I doing wrong?

rv0’s picture

what the status of this patch
is it in dev or.. ?

userok’s picture

subscribe

dawehner’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev

Commited #984794: Create API for non-node forms and used your patch to implement the feature

It worked fine for me, so feel free to try it out now.

This has to be ported to d7.

dawehner’s picture

Status: Needs review » Patch (to be ported)

Update status.

Rosamunda’s picture

After reading all these posts I realize that this is (now) about 7.x version.
But the 6.x version won´t work in my case.
All limiting options appear except the ones related to comments.
I have the 2.0-beta2 version installed.
How can I make it work? The readme file doesn´t explain about how to limit comment´s length.
Thanks for your help!
Rosamunda

Rosamunda’s picture

Any thoughts?

jm.federico’s picture

Status: Patch (to be ported) » Closed (won't fix)

7.x-3.x allows you to set the counter on any field, including the comment body.

Marking as won't fix.

Rosamunda’s picture

Hi again,
Why is this marked as won´t fix? I mean those patches won´t work... ever?
Is there any way to limit character count inside comments, in 6.x?
Thanks again!

jm.federico’s picture

I'm not the maintainer of branch 6.x, but I thought for comment #48 that it had been commited.
As for branch 7.x-2.x it is not under development anymore. Branch 7.x-3.x has the functionality, hence marked as won't fix for branch 7.x-2.x.

If version 6.x-2.x still doesn't have the functionality, please feel free to re-open the ticket, but please make sure to specify why you are re-opening it.

Rosamunda’s picture

Thanks for your reply. But where´s the UI? I´ve looked for a limit under admin/content/node-type, and did find "limit body length" and "limit title length", but nothing about limiting comments length...

userok’s picture

i've just tried the latest Dev version ( October 23, 2011) everything is there. Under your Content Type>Comment Settings, there should be "Comment_comment max length" input field.
Works great!

Rosamunda’s picture

You´re rigth! THANKS! I didn´t tried the "dev" version!

schnitzel’s picture

yes you should use the 3.x version instead of the 2.x.
The 2.x was just a small and fast port to D7, where 3.x is a rebuild of the functionalities.
There is a 2.x to 3.x upgradepath.