-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TokenProcessor - Allow basic filter/modifier expressions #21428
Conversation
This will allow more complicated token expressions.
(Standard links)
|
Cool - I have a feeling that |upper would already be pretty useful (I'm sure I've written tokens in the past to do just that....) |
test fails relate |
Before ------ `Hello {foo.bar}` After ----- `Hello {foo.bar|upper}` and `Hello {foo.bar|lower}` Technical Details ----------------- This only supports tokens that supply values through `civi.token.eval`. At the time of this commit, most `{contact.*}` tokens still use `TokenCompatSubscriber::onRender()` to hack-in their values and won't work until they switch over. The regex which recognizes the filter is pretty tight (`\w+`). This can be relaxed somewhat by a subsequent change, but I'd say such a change has a burden to demonstrate safety/interoparbility when running in Token-Smarty format. (e.g. demonstrate that matching of open/close symbols works correctly).
74a061d
to
fb4ab62
Compare
Ah, it wasn't working on pseudo-tokens with a |
@totten I'm gonna give this merge-ready. It seems useful in itself & it works but obviously the real value is when we extend for dates. I've put a note in the dev-digest |
Looks good to me too. |
Overview
This demonstrates how to extend
TokenProcessor
to support rendering token-expressions with filters/modifiers.ping @eileenmcnaughton @mattwire
Before
Hello {foo.bar}
After
Hello {foo.bar|upper}
andHello {foo.bar|lower}
Technical Details
This only supports tokens that supply values through
civi.token.eval
(ie$row->token(...key-value...)
). At the time of this commit, most{contact.*}
tokens still useTokenCompatSubscriber::onRender()
to hack-in their values and won't work until they switch over.The regex which recognizes the filter is pretty tight (eg accepting
|upper
or|lower
but not|myfunc:"yadda yadda"
). This can be relaxed somewhat by a subsequent change, but I'd say such a change has a burden to demonstrate safety/interoparbility when running in Token-Smarty format. (e.g. demonstrate that matching of open/close symbols works correctly).