Problem/Motivation
Using tokens in the text currently leads to cut-off and thereby broken tokens, when trimming happens inside the token, for example:
[custom:this-is-my-token]
or
[site:logo:theme:very-long-string]
or
This is a node teaser text which uses the [site:url] token
will be cut off, if hit by the trim length and the token won't be replaced. Displayed result for example:
This is a node teaser text which uses the [site:u...
Steps to reproduce
See above
Proposed resolution
Tokens have to be replaced before trimming the text to return the expected, correctly trimmed result
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork smart_trim-3301743
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodyThis is closely related to #2041053: Add option to strip Media module code (D7) eventhough the media entities are not real tokens.
Comment #4
anybodyMade a first shot, for further improvements this could be heavily inspired by https://www.drupal.org/project/token_filter
We should also add tests with at least site tokens to ensure it works as expected.
Comment #5
anybodyAs these changes affect several places in the file, I decided to combine this and do a cleanup of the token logics in smart_trim.
Please review :) If everything is fine at manual testing, we'll write some tests.
Comment #6
anybodyComment #8
grevil commentedDoes not work currently with trim_type "chars"
Example:
Formatter Settings (on body from bundle article):
Test string = "Test [node:content-type]"
Expected Result: "Test Artic"
Actual Result: "Test"
See failing tests for more informationEdit: "Testing is generally disabled for this module"Comment #9
anybodyThanks @Grevil, I created a separate issue for testing: #3308865: Write tests and enable automated testing
Let's see if we can fix that. Anyway I don't think it's due to this error and was wrong before already. Good tests :)
Comment #10
anybody@Grevil: I found it and created an issue: #3308868: Unclear trimming behavior (whole words or not?) - missing setting
So please change the expected test result and add a comment with the issue link above, that this may change in future versions.
Expected result is now "Test" as it's the whole word BEFORE the char count.
Comment #11
grevil commentedDone! All tests are green locally.
Comment #12
anybodyThanks @Grevil! :)
Comment #13
anybodyAny active maintainer to have a look?
Comment #14
markie commentedI am liking this code and how it works, but I am having a hard time manually testing this. Can you write up some text instructions please?
Comment #15
grevil commented@markie sure thing!
Comment #17
markie commentedAwesome.. Makes so much more sense now. Committed and will be in the next release.
Comment #18
anybodyHi @markie, thanks! We'd still like to offer our help as Co-Maintainers, if you'd like to.