Skip to content

Commit 6ae6a9f

Browse files
committed
Implement else clause
1 parent c0b0f26 commit 6ae6a9f

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Classes/Domain/Finishers/EmailFinisher.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ function($match) use ($formValues) {
5555
$operation = $match[2];
5656
$operandTwo = $match[3];
5757

58+
list($thenValue, $elseValue) = GeneralUtility::trimExplode('{else}', $match[4], true);
59+
#debug([$thenValue, $elseValue]);
60+
5861
if (isset($formValues[$operandOne])) {
5962
$operandOneValue = $formValues[$operandOne];
6063
}
@@ -69,28 +72,28 @@ function($match) use ($formValues) {
6972
case '==':
7073
case '===':
7174
if ($operandOneValue == $operandTwoValue) {
72-
return $match[4];
75+
return $thenValue;
7376
}
74-
return '';
77+
return $elseValue ?? '';
7578
case '>':
7679
case '>':
7780
if ($operandOneValue > $operandTwoValue) {
78-
return $match[4];
81+
return $thenValue;
7982
}
80-
return '';
83+
return $elseValue ?? '';
8184
case '<':
8285
case '&lt;':
8386
if ($operandOneValue < $operandTwoValue) {
84-
return $match[4];
87+
return $thenValue;
8588
}
86-
return '';
89+
return $elseValue ?? '';
8790
case '!=':
8891
case '<>':
8992
case '&lt;&gt;':
9093
if ($operandOneValue != $operandTwoValue) {
91-
return $match[4];
94+
return $thenValue;
9295
}
93-
return '';
96+
return $elseValue ?? '';
9497
case 'in':
9598
// example: {if:multicheckbox-1:in:dog,cat}
9699

@@ -101,10 +104,11 @@ function($match) use ($formValues) {
101104

102105
foreach ($operandOneValue as $value) {
103106
if (in_array($value, $operandTwoValue)) {
104-
return $match[4];
107+
return $thenValue;
105108
}
106109
}
107-
return '';
110+
111+
return $elseValue ?? '';
108112
}
109113
},
110114
$message

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ you've selected {if:singleselect-1:=:}nothing{endif}{if:singleselect-1:=:1}apple
4242
4343
And your other input is within an array: {if:multiselect-1:in:cat,dog,hamster}it's a pet{endif}
4444
45+
Apparently you like {if:selectsingle-1:=:1}bikes{else}walking{endif}
46+
4547
Good bye.
4648
```

0 commit comments

Comments
 (0)