My forum members post extremely lengthy forum topics and subsequent comments. I successfully edited the forum template to use [node:summary], via the fix_core module, to set the trim length for forum topics, but cannot find a method to trim [comment:body]. Can php be used within the mail template to trim the [comment:body] token, since it doesn't have an actual "teaser" setting? Or is there a more direct approach that I am somehow missing?

Comments

shivachevva’s picture

To trim [comment:body] in forum template, you create a custom token for comment body and replace the custom token instead of [comment:body]. To create custom token to visit http://drupal.org/node/1308488.

molika4’s picture

When I used Custom Tokens (project/token_custom), enabled core PHP filters, and created a basic text replacement token, not even trying to call any actual data, the raw token value php shows up inside the e-mail preview window surrounded by html paragraph tags. All caches have been cleared.
Inside of Mail Editor, the php of the token is not being filtered (evaluated?) and replaced with the actual value of the token.

salvis’s picture

Title: How to trim [comment:body] in forum template » How to trim [comment:body] in forum template -- implement [comment:summary]
Category: support » feature

No, there is currently no way to provide a shortened version of [comment:body].

Neither Subscriptions nor Mail Editor will run user-provided PHP code. If you have a module that claims to do that, then that module must run the code. Be aware that this could easily put your site at risk.

The broken [node:summary] is certainly a case for Fix Core, but [comment:summary] would be a new feature that does not currently exist. The primary place for such a feature would be the Token module or even core.

If that doesn't work out, we could add it to Subscriptions. Based on the code in Fix Core and Subscriptions, it shouldn't be too hard to do.

molika4’s picture

Thank you for the confirmation. I was aware of some concerns regarding php vulnerability, depending on the usage. It looks like a custom module will be required for the function I need, so I will get to work on that. Meanwhile, if you think this is something that should be requested for Token module or even core, what would be a next step? Alternatively, what would be a next step for adding it to Subscriptions?
(personal note: Subscriptions module is one I selected after much research -- I really like your module and appreciate what you've done with it and Mail Editor.)

salvis’s picture

Thank you for the kind words.

The way to get this into Core or Token is to post a feature request in the respective queue, preferably with a patch, and even better with a patch including a test.

If you look at how fast #1350902: Should you be stripping tags before trimming is moving, you can estimate how long it would take in Core though. I haven't followed the Token queue and can't say what your chances are there, but that would be the proper place IMO, because it could be useful in contexts other than Subscriptions.

If you get no positive response in the Token queue, then look at subscriptions_content.tokens.inc to see what it takes to implement additional tokens in Subscriptions and at the summary fix in Fix Core to come up with a patch for Subscriptions.

Here's another idea: go to admin/structure/types/manage/forum/comment/display, enable the Tokens custom display and set the Tokens custom display format of the comment field to Trimmed. I haven't actually tried this, but I think it should give you what you want (provided you don't need the full [comment:body] token in any other context).

molika4’s picture

Thanks for the follow-up. Will look at the Token queue -- that's a good point about using it in other contexts.
As for creating a custom display for Tokens for comments, I had already tried that and it will trim the comment if I use the [comment:body] token in a View, but the mail editor receives the actual token, rather than a derived view, so no cigar :-(

salvis’s picture

the mail editor receives the actual token, rather than a derived view

Getting its own view mode merits opening a new feature request in the Mail Editor queue.