TokenProcessor - Allow basic filter/modifier expressions
authorTim Otten <totten@civicrm.org>
Thu, 9 Sep 2021 23:26:08 +0000 (16:26 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 10 Sep 2021 06:02:20 +0000 (23:02 -0700)
commitfb4ab6230ee38e9e5d12b6a239598ee6fe92c3af
tree2449aa120a01f4718042025b96be2dd1e50fe762
parentc7ab366b9126babdc164e01cbc21dc840f8fe6e6
TokenProcessor - Allow basic filter/modifier expressions

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).
Civi/Token/TokenProcessor.php
tests/phpunit/Civi/Token/TokenProcessorTest.php