Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

token_modifier

290 sites Security covered
View on drupal.org

Token modifier provides a meta token that allows you to modify the output of other tokens.

Usage

To use these token modifiers, you simply add a prefix to your existing token.

[token-modifier:{modifier}:{existing token}]

The modifiers should work anywhere the existing token would work. It passes through all the context available to the original token.

For example: output the current users' username as title case:

[token-modifier:title-case:current-user:name]

Included modifiers

  • urlencode: URL Encodes the returned string.
  • title-case: Uppercases the first letter of each word using ucwords.
  • uppercase: Uppercases all characters.
  • lowercase: Lowercases all characters.
  • uppercase-first: Uppercases the first letter of the string.
  • length: Limits the maximum length of the string.
    e.g. [token-modifier:length:8:current-user:name]
  • trim: Strips whitespace from the beginning and end of a string.
  • ltrim: Strips whitespace from the beginning of a string.
  • rtrim: Strips whitespace from the end of a string.
  • strip-tags: Removes HTML tags.

Chaining

Chaining modifiers is possible. Just keep prepending token-modifier:{modifier} to the front of the token.

Extend (D7 only)

Token Modifiers uses the ctools plugin system to allow other modules to provide their own modifiers.

To get started:

  1. Copy one of the existing plugin files within token_modifier/plugins/token_modifer to a plugins/token_modifier folder in your module and modify the details. The filename of your .inc file is used in the token.
  2. Implement hook_ctools_plugin_directory in your module. Look at token_modifier_ctools_plugin_directory as an example.

Contributing

I'll gladly bundle more modifiers that I think are going to be widely useful. Create an issue in the issue queue (ideally with a patch ready to go) and I'll take a look.

Contributed Modifiers

These modifiers have been contributed but haven't been included in the main module due to a narrow use-case, however you can implement the plugins in your own custom module.

Activity

Total releases
4
First release
Jan 2025
Latest release
5 months ago
Release cadence
99 days
Stability
100% stable

Release Timeline

Releases

Version Type Release date
2.0.6 Stable Nov 17, 2025
2.0.4 Stable Aug 6, 2025
2.0.3 Stable May 22, 2025
2.0.2 Stable Jan 25, 2025