Drupal is a registered trademark of Dries Buytaert
drupal 11.4.0 Update released for Drupal core (11.4.0)! drupal 10.6.12 Update released for Drupal core (10.6.12)! drupal 11.3.13 Update released for Drupal core (11.3.13)! drupal 10.6.11 Update released for Drupal core (10.6.11)! drupal 11.3.12 Update released for Drupal core (11.3.12)! drupal 11.2.14 Update released for Drupal core (11.2.14)! drupal 10.5.12 Update released for Drupal core (10.5.12)! cms 2.1.3 Update released for Drupal core (2.1.3)! drupal 10.5.11 Update released for Drupal core (10.5.11)! drupal 11.3.11 Update released for Drupal core (11.3.11)! drupal 11.2.13 Update released for Drupal core (11.2.13)! drupal 10.6.10 Update released for Drupal core (10.6.10)! cms 2.1.2 Update released for Drupal core (2.1.2)! drupal 11.1.10 Update released for Drupal core (11.1.10)! drupal 10.5.10 Update released for Drupal core (10.5.10)! drupal 10.4.10 Update released for Drupal core (10.4.10)! drupal 11.2.12 Update released for Drupal core (11.2.12)! drupal 11.3.10 Update released for Drupal core (11.3.10)! drupal 10.6.9 Update released for Drupal core (10.6.9)! drupal 10.6.8 Update released for Drupal core (10.6.8)!

Enforces different character limits on text fields based on the current user's roles. Limits are configured per field instance and enforced via a typed data constraint on the server side. A live character counter is provided via a Stimulus.js controller.

Features

The core maxlength field property enforces a single hard limit for all users. This module extends that concept by allowing site builders to define different limits per role on any string or text field. The highest limit
across all of a user's roles is applied (see resolution rules below).

Common use case: a microblogging platform where standard users can post up to 500 characters and journalists can post up to 1,200 characters.

Post-Installation

1. Open the Manage form display page for your field

Navigate to the Manage form display page for the entity type and bundle
containing the field you want to limit (e.g.
/admin/structure/comment/manage/chirp/form-display).

2. Configure the field widget settings

Click the gear icon next to the field widget and expand the
**Role-aware character limits** section.

Setting Description Default limit Applies to all authenticated users. Acts as the fallback when no role-specific limit matches. Leave blank for no default limit. Limit per role One field per configured role. Leave blank to fall back to the default limit for that role.

3. Attach the constraint

The typed data constraint must be explicitly attached to the field instance.
This can be done in code:

<?php

$fieldConfig = FieldConfig::loadByName('comment', 'chirp', 'comment_body');
$fieldConfig->addConstraint('RoleAwareMaxlength');
$fieldConfig->save();

?>

Or via an update hook or hook_install() in your custom module.

  • Note: Future versions of this module may attach the constraint
  • automatically when limits are configured. For now, explicit attachment
  • is required.

4. (Optional) Use the provided widget

Switch the field widget to Textarea (role-aware maxlength) to get the
live character counter and the correct `maxlength` attribute automatically.
For CKEditor fields, the counter is rendered via the hook_field_widget_third_party_settings_form() integration — see the project README.md.

Additional Requirements

- Drupal ^11.3
- drupal:field
- drupa:user

Supporting this Module

This module is supported by Lisa Harrison (lisa.rae), an individual contributor and long-time member of the Drupal community.

Activity

Total releases
1
First release
Jul 2026
Latest release
1 day ago
Release cadence
Stability
0% stable

Releases

Version Type Release date
1.0.0-beta1 Pre-release Jul 2, 2026