diff --git a/Civi/Token/TokenProcessor.php b/Civi/Token/TokenProcessor.php index 1ed89df5fc60..a5434e138d19 100644 --- a/Civi/Token/TokenProcessor.php +++ b/Civi/Token/TokenProcessor.php @@ -508,6 +508,14 @@ private function filterTokenValue($value, ?array $filter, TokenRow $row) { return $value; } + case 'default': + if (!$value) { + return $filter[1]; + } + else { + return $value; + } + default: throw new \CRM_Core_Exception('Invalid token filter: ' . json_encode($filter, JSON_UNESCAPED_SLASHES)); } diff --git a/tests/phpunit/Civi/Token/TokenProcessorTest.php b/tests/phpunit/Civi/Token/TokenProcessorTest.php index b606ca4c28b6..d3eff21d4c85 100644 --- a/tests/phpunit/Civi/Token/TokenProcessorTest.php +++ b/tests/phpunit/Civi/Token/TokenProcessorTest.php @@ -350,9 +350,11 @@ public function testFilter(): void { 'This is {foo_bar.whiz_bang|upper}!' => 'This is SOME TEXT!', 'This is {foo_bar.whiz_bang|boolean}!' => 'This is 1!', 'This is {foo_bar.whiz_bop|boolean}!' => 'This is 0!', + 'This is {foo_bar.whiz_bang|default:"bang"}.' => 'This is Some Text.', + 'This is {foo_bar.whiz_bop|default:"bop"}.' => 'This is bop.', ]; - // We expect 5 messages to be parsed 2 times each - ie 10 times. - $expectExampleCount = 10; + // We expect 7 messages to be parsed 2 times each - ie 14 times. + $expectExampleCount = 14; $actualExampleCount = 0; foreach ($exampleMessages as $inputMessage => $expectOutput) {