Smart Trim Tokens for text with summary fields

Created on 11 August 2016, over 8 years ago
Updated 26 August 2024, 4 months ago

In trying to get the metatags module to use a sensibly trimmed and cleaned version of a field, I came to the conclusion it would be really useful to have tokens exposed for textarea fields.

Preferably this token should be dynamic so that an argument of trim length can be passed in, this broadens the usefulness of the tokens.

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇿🇦South Africa duncan.moo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • heddn Nicaragua

    I'm sure the implementation between D7 and D10 is a little different. But a smart trim token for summary fields is actually a missing feature-set in D10 too. And since the life-support for D7 is so short at this point, I'm going to just move versions and work on a version of these functionality for the 2.1.x version.

  • heddn Nicaragua

    heddn changed the visibility of the branch 2.1.x to hidden.

  • Merge request !94Initial implementation of a smart trim token → (Merged) created by heddn
  • heddn Nicaragua

    Initial implementation in smart trim 2.1.x provided.

  • Pipeline finished with Failed
    7 months ago
    Total: 623s
    #190890
  • Status changed to RTBC 7 months ago
  • 🇺🇸United States akalata

    Works as expected, though I'm not sure about the assumption of a `token` view mode -- but I think that's more of a foundational approach with "how do we handle tokens that might need to respond to settings?".

  • heddn Nicaragua

    The 'token' view mode logic is exactly what token.module assumes. It seems like that assumption was a safe one to continue using here too.

  • First commit to issue fork.
  • Status changed to Needs work 5 months ago
  • 🇺🇸United States ultimike Florida, USA

    Thanks everyone for pushing this issue forward, and also for your patience for one of this module's slacker maintainers finds the time to check it out (present company included).

    First off - this needs a test. @markie and I have been really trying to require tests for all feature additions and bug fixes, so this would be no exception. I think a functional test would be pretty straight-forward...

    I manually tested this using Gitpod with a few of our DrupalEasy alums and all appears to work as expected. The only thing I would make note of (possibly with an update to the README and/or docs) is the fact that the Token view mode must be enabled and configured with a Smart Trim formatter (for the field(s) in question) or the Smart Trim tokens aren't really involved.

    Regardless, we tested Smart Trim tokens with Pathauto and Metatag with everything working as expected.

    I went ahead and committed @heddn and @akalata's suggestions, as well as a PhpStan ignore for renderPlain() in smart_trim.tokens.inc (see 📌 Handle renderPlain() deprecation Active ).

    -mike

  • Status changed to Needs review 5 months ago
  • heddn Nicaragua

    Test coverage added.

  • Pipeline finished with Failed
    5 months ago
    Total: 140s
    #233217
  • Status changed to Needs work 5 months ago
  • 🇺🇸United States markie Albuquerque, NM

    Needs a rebase please.

  • First commit to issue fork.
  • Pipeline finished with Failed
    5 months ago
    Total: 209s
    #237559
  • Pipeline finished with Failed
    5 months ago
    #237571
  • Pipeline finished with Failed
    5 months ago
    Total: 212s
    #237586
  • Pipeline finished with Failed
    5 months ago
    Total: 187s
    #237611
  • heddn Nicaragua

    heddn changed the visibility of the branch 2782455-smart_trim_summary_token to hidden.

  • Pipeline finished with Failed
    5 months ago
    Total: 292s
    #238776
  • Pipeline finished with Failed
    5 months ago
    Total: 204s
    #238780
  • Pipeline finished with Failed
    5 months ago
    Total: 309s
    #239620
  • Status changed to Needs review 5 months ago
  • heddn Nicaragua

    This should now be green, except for Drupal 11 support. Which is still not functional on HEAD.

  • Pipeline finished with Failed
    5 months ago
    Total: 231s
    #239638
  • Pipeline finished with Failed
    5 months ago
    Total: 282s
    #239645
  • 🇮🇳India ankitv18

    ankitv18 changed the visibility of the branch 2.1.x to active.

  • 🇮🇳India ankitv18

    ankitv18 changed the visibility of the branch 2782455-smart_trim_summary_token to active.

  • 🇮🇳India ankitv18

    ankitv18 changed the visibility of the branch 2.1.x to hidden.

  • 🇮🇳India ankitv18

    ankitv18 changed the visibility of the branch 2782455-smart-trim-tokens-7.x to hidden.

  • Pipeline finished with Success
    5 months ago
    Total: 188s
    #239652
  • heddn Nicaragua

    In #39 thought I had it figured out why tests are failing on pre 10.2. They pass successfully on local 10.2, just not on the testbot. Since 10.1 is no longer supported and this is a new feature, I feel quite happy to simply skip execution on old drupal versions (that's what we do now). It results in the same work later since in both cases we'd have pre 10.2 logic that would need to be removed.

  • Status changed to Needs work 5 months ago
  • 🇺🇸United States ultimike Florida, USA

    I changing this to "needs work", but for any serious reason - only because I have a question about the test logic that I couldn't figure out on my own...

    thanks,
    -mike

  • Status changed to Needs review 5 months ago
  • heddn Nicaragua

    Comment posted.

  • 🇺🇸United States markie Albuquerque, NM
  • Status changed to RTBC 5 months ago
  • 🇺🇸United States markie Albuquerque, NM

    Tested in Drupalpod with metatag and it seems to be working well. Was able to update the metatag description with a token.

  • Pipeline finished with Skipped
    5 months ago
    #247272
    • markie committed 31bfff67 on 2.x authored by heddn
      Issue #2782455 by heddn, duncan.moo, voleger, ankitv18, ultimike, Chris...
  • Status changed to Fixed 5 months ago
  • 🇺🇸United States markie Albuquerque, NM

    Merged and prepping for the next release.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇬🇧United Kingdom jacobupal Leeds

    I've just tried this out and while [node:body-smart-trim] alone will work, when I use it as a meta tag description [node:body-smart-trim:160] i.e. including a max-length value, it does not. The page simply loads without the appropriate meta tag present. Presumably because "[node:body-smart-trim:160]" could not be found.

    So two questions:

    1. Am I using the token correctly?
    2. If I can't enter a character limit, what the default character limit being used?
  • 🇺🇸United States ultimike Florida, USA

    @jacobupal,

    No, tokens that include a max-length value are not supported.

    When using the new Smart Trim token, the max value (and the rest of the settings) will come from the Token view mode of the entity (if specified) or fallback to the default view mode settings.

    -mike

  • heddn Nicaragua

    Exactly what Mike said in #53. That is how core tokens work too. This is just following that precedent.

Production build 0.71.5 2024