Hello. I am using ckeditor 7.x-1.15 and i tried using Maxlength module. enabled and clear the caches. I add 120 characters for maxlength but it is not showing when I edit the form. Can you help me? The counter and the ckeditor is not being limited.

Comments

mschudders’s picture

I can confirm this.

However it is working on the Title field of a content type but not on text areas on the content type.

Tried with Ckeditor 3.6.6.2 & 4.5.3 & just plain text.

Tried with a single text area, and with field collections containing text areas.

jagadmarx’s picture

Maxlength doesn't work for me too even using plain text fields and text area. Is there a fix for this?

flbr’s picture

I too have this problem. I don't see maxlenght.js included anywhere. I included it manually, but it didn't fix it.

bhavikshah9’s picture

I have faced same problem as mentioned by @flbr.
I have activated module, flushed cache and tried. But, not working.
I have tried with plain text, textarea and along with CKeditor. But, it didn't worked in any case.
I have checked source code and found that maxlength.js in not included in code.

adiatis’s picture

Same problem here on a flat textarea without editor. Can I check something?

ncameron’s picture

By default the count does not show for UID 1 / admin. Try logging in as a regular user.

nicrodgers’s picture

This caught me out at first, too. The Administrator role (not just UID 1) has the permission 'bypass max length' assigned by default, so you don't see it whilst logged in as admin. I think we should either update the documentation to state this, or preferably, change the default behaviour so that no roles are automatically assigned the bypass permission. What does everyone else think?

campsjos’s picture

I lost all the day because of this...
This should be on the documentation :(

bdombro’s picture

The Administrator role (not just UID 1) has the permission 'bypass max length' assigned by default, so you don't see it whilst logged in as admin.

This doesn't seem to be disabled, either. +1 that it should not be default, and should definitely be in the documentation.

nicrodgers’s picture

I have updated the documentation to explain the default permission setup/behavior.

https://www.drupal.org/node/1303664

nicrodgers’s picture

StatusFileSize
new587 bytes

Uploading a patch to the README.txt to explain that the default configuration means Administrators wont see the counter.

nicrodgers’s picture

Version: 7.x-3.0 » 7.x-3.x-dev
Status: Active » Needs review
dkre’s picture

+1 disabled by default.

I'm not sure of the use case where you want to input a longer value than the users you're building for.

Great module though :)

khumbu’s picture

Just came across this and don't get it either...what is/was the thought behind this? I would also disable this by default...it will help a lot of people (like me).

dqd’s picture

Well, this issue could possibly come up even if your admin permissions are set up correctly ...

samtny’s picture

My two cents is that the field should still show the configured 'max length', but explicate a bit, e.g.;

"The max length for this field has been configured to allow 310 characters, however your permissions allow you bypass this limit..."

dgtlmoon’s picture

StatusFileSize
new2.48 KB

I found that even with 'bypass maxlength' permission DISABLED for "Administrator" role it was still allowing the administrator to bypass the role (because user_access will always say that UID 1 has access to everything)

I added a small function to factor this and included the original README.txt patch which will be incorrect without the extra tweak to access functionality

kopeboy’s picture

I can confirm that after setting the permission to bypass off I still can't see the counter on fields as admin..

zmove’s picture

+1 for that patch to be commited, its very annoying when you make a website, to not see what you are setting up about maxlength.

quotientix’s picture

+1 for changing the default setting or even better displaying a message for the superuser.

kumkum29’s picture

+1
User 1 should see the counter.

youngwolf0’s picture

+1 to seeing this as an administrator, just lost a couple of hours to this thinking I was doing something wrong.

caspervoogt’s picture

patch from #17 fixes this. I had noticed the admin role was set by default to bypass maxlength restrictions... but that was not working and maxlength was not happening. I then removed that permission from the admin role, and nada. This patch solved it. +RTBC

daskausikdas’s picture

In my case maxlength is considering the html text though I checked 'Truncate html' option. Is there any patch to solve this problem?

daskausikdas’s picture

I have used ckeditor..

jimafisk’s picture

#17 patch worked for me, thank you dgtlmoon!

bgrobertson’s picture

It should definitely disabled by default. I used this drush command to get it working:
drush vset maxlength_always_for_uid1 1

You can also add this to your settings.php:

// Add "$conf['maxlength_always_for_uid1'] = TRUE;" to settings.php to activate
// for user #1.
danny englander’s picture

StatusFileSize
new1.93 KB

The patch in #17 failed but only as it had drupal.org packaging information for the info file. I have excluded that and updated. It now works to solve the issue logged in a user 1, I see the counter and it works as expected. Thanks @dgtlmoon.

capellic’s picture

This patch needs work. It assumes that the administrator role is named "administrator". On our sites, the role is "drupal admin". So not only does this nor work, it throws PHP warning messages:

$admin_role = user_role_load_by_name('administrator');

Why not use the administrator role defined by the "Administrator role" field (variable name "user_admin_role") on the account config page (admin/config/people/accounts)? Here's what I came up with:

function _maxlength_user_access_bypass() {
  global $user;

  $bypass = FALSE;
  // #2415823 Admin user when calling user_access is always true
  if ($user->uid == 1) {
    if (!$bypass = variable_get('maxlength_always_for_uid1', FALSE)) {
      // Examine the roles
      $admin_role_rid = variable_get('user_admin_role');
      if ($admin_role_rid) {
      	$admin_role = user_role_load($admin_role_rid);
	$roles = array($admin_role->rid => $admin_role->name);
    	$permissions = user_role_permissions($roles);
	$bypass = isset($permissions['bypass maxlength']) && $permissions['bypass maxlength'] ? TRUE : FALSE;
      }
    }
  }
  else {
    $bypass = user_access('bypass maxlength');
  }

  return $bypass;
}
quiron’s picture

Hi,

I have the same issue. My patch is more drastical, for me the bypass function has no utility so I removed it. For me this is working cause nobody will be able to bypass maxlength.

Hope can be useful for someone

firfin’s picture

With patch from #28 the counter show for all fields. Without the patch it always shows just for title.
We are getting close, but not there yet?

As for #29, why not just change it to
// Examine the roles
$permissions = user_role_permissions(user_role_load(variable_get(user_admin_role,'administrator')));

If you changed the role_id, then user_admin_role is set as a variable. And if it wasn't set it is 'administrator'.
Or if there is no admin role set it will return no permissions. So this should always work?

kala4ek’s picture

Status: Needs review » Active

I think we should not remove bypass functionality.
I guess it will be better to inform user that he have bypass permission and show limit of chars for this field.

sumthief’s picture

I sympathize with the patch #30.
Because bypass characters limit looks like dangerous functional for me.
I mean that when we use maxlength module and we set limit to the textfield length we can trust that it will have quantity of characters less than or equal to limit. So bypass permission given to users can broke some output for example.
But I'm not sure that my opinion coincides with the opinion of all users.

IRuslan’s picture

As I see there is an option to show limit for super admin if you set up 'maxlength_always_for_uid1' variable.
But I think it worth to have a default value for it as TRUE.

emmanvazz’s picture

I also think it should be off by default. I got confused and had to come to the issues queue to find out that there was a bypass and everything was actually working correctly.

Also when I do turn the bypass off, it still doesn't seem to enforce the max-length.

kala4ek’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB

Update the patch according to the last conversation.

Anonymous’s picture

#36 is simple and elegant at this point.

Although I'd expect this kind of a function to be built-in in the module and be controllable through the UI.

roam2345’s picture

Status: Needs review » Reviewed & tested by the community

woks for us marking this as RTBC as was really confused was not seeing this no where was documented about this for admin users.

mohaly’s picture

Hello every one, dose any one use this module with D8, I can't apply it to the body field, any suggestions !?

dkre’s picture

bassplaya’s picture

Thank you @nicrodgers !

It should also be in the latest stable version. 7.x-3.3 as of now.
I feel that if more modules would have great accompanying documentation i.e. README.txt than Drupal and the entire community would really benefit from it so much more. I'm gonna give back on this once I find the time. Explore the awesome modules I've am using each time that have robbed me of so much precious time. It's a complaint I see over and over again in the issue queues. I am committed to doing something about that. You can count on me and hold me accountable.

cedewey’s picture

Title: Counter / Maxlength not working / showing up. » Disable bypass maxlength permission for administrators by default.
Category: Bug report » Feature request
Status: Reviewed & tested by the community » Closed (works as designed)

Hi all,

I've updated the title of the issue and marked this as a feature request for clarity. We are only actively maintaining the Drupal 8/9 version of Maxlength from here on out.

I do appreciate everyone's contributions to this issue. I can see the value in changing the default behavior. If someone is willing to volunteer to maintain the Drupal 7 version please reach out. Otherwise, I encourage everyone to upgrade their websites to Drupal 8/9.

Also, we will be working on addressing what is essentially the opposite problem in the D8/9 version :P https://www.drupal.org/project/maxlength/issues/3195874