Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

About

Trims content from the left or right from a set offset and an optional length as a full on Drupal field formatter.

I hadn't found a good way to trim from the left using the Drupal interface. The
PHP substr function seemed a good way to go about it, and there's some extra functionality to boot! For more advanced functionality and examples, read the official PHP documentation linked above. :)

Usage

There are two input fields, the first is the offset parameter and the second is length.

Offset Parameter

A negative value will trim all characters from the start of the string until
the specified character count from the end of the string (trimming from the
left), a positive value will do the opposite and trim from the right. For the
string "abcdef", 2 would output "cdef" and -2 would output "ef"'.

Length Parameter

Sets the string length to a fixed number of characters. For the string "abcdef"
, with a start/offset position of 2, a trim length of 1 would output "c" and a
trim length of -1 would output "cde".

Aside

For views you could use Twig 2's Slice Filter in a rewrite or global text field, there are instances where using a field formatter works smoother (passing information to Charts, Simple Math, etc). If this works for you you'd have one less contrib module installed, though things could get a little clunky!

I was playing around with having radio buttons for end/left, start/right direction, then having logic multiply by -1 to an absolute value of start - it might be a little more intuitive from a user standpoint, but it ended up being simpler just keeping it the same structure as the PHP function. If there's enough interest that could warrant an extra branch.

Depends on

Dependencies of the latest stable release

  • text Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Jan 2023
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Slowing

Release Timeline

Releases

Version Type Core Release date
1.2.0 Stable 8–11 Sep 17, 2024
1.1.0 Stable Feb 1, 2023
1.0.3 Stable Jan 31, 2023