22declare (strict_types = 1 );
33namespace Kitzberger \FormMailtext \Domain \Finishers ;
44
5+ use TYPO3 \CMS \Core \Utility \GeneralUtility ;
56use TYPO3 \CMS \Fluid \View \StandaloneView ;
67use TYPO3 \CMS \Form \Domain \Runtime \FormRuntime ;
78
@@ -32,7 +33,7 @@ protected function initializeStandaloneView(FormRuntime $formRuntime, string $fo
3233 private function replaceIfs ($ message , $ formValues )
3334 {
3435 return preg_replace_callback (
35- '/{if:([a-z0-9\-_]+):(. +):([a-z0-9\-_]*)}(.*)({endif})/sU ' ,
36+ '/{if:([a-z0-9\-_]+):([^:] +):([a-z0-9\-_, ]*)}(.*)({endif})/sU ' ,
3637 function ($ match ) use ($ formValues ) {
3738 #debug($match, 'a match!');
3839
@@ -55,31 +56,41 @@ function($match) use ($formValues) {
5556 case '=== ' :
5657 if ($ operandOneValue == $ operandTwoValue ) {
5758 return $ match [4 ];
58- } else {
59- return '' ;
6059 }
60+ return '' ;
6161 case '> ' :
6262 case '> ' :
6363 if ($ operandOneValue > $ operandTwoValue ) {
6464 return $ match [4 ];
65- } else {
66- return '' ;
6765 }
66+ return '' ;
6867 case '< ' :
6968 case '< ' :
7069 if ($ operandOneValue < $ operandTwoValue ) {
7170 return $ match [4 ];
72- } else {
73- return '' ;
7471 }
72+ return '' ;
7573 case '!= ' :
7674 case '<> ' :
7775 case '<> ' :
7876 if ($ operandOneValue != $ operandTwoValue ) {
7977 return $ match [4 ];
80- } else {
81- return '' ;
8278 }
79+ return '' ;
80+ case 'in ' :
81+ // example: {if:multicheckbox-1:in:dog,cat}
82+
83+ if (!is_array ($ operandOneValue )) {
84+ $ operandOneValue = [$ operandOneValue ];
85+ }
86+ $ operandTwoValue = GeneralUtility::trimExplode (', ' , $ operandTwoValue , true );
87+
88+ foreach ($ operandOneValue as $ value ) {
89+ if (in_array ($ value , $ operandTwoValue )) {
90+ return $ match [4 ];
91+ }
92+ }
93+ return '' ;
8394 }
8495 },
8596 $ message
0 commit comments