N°8772 - Expressions inputs are now :input instead of [[input]] (and quotes are added automatically)

This commit is contained in:
Eric Espie
2025-11-14 14:05:22 +01:00
parent dc1ce2dc64
commit 891df6ab1c
2 changed files with 30 additions and 6 deletions

View File

@@ -13,13 +13,14 @@ use Combodo\iTop\Forms\Register\IORegister;
use Combodo\iTop\Forms\FormsException;
use IssueLog;
use Symfony\Component\Form\FormEvents;
use Throwable;
/**
*
*/
class ExpressionFormBlock extends AbstractFormBlock
{
public const EXPRESSION_PATTERN = "/\[\[(?<input>[^\]]+)]]/";
public const EXPRESSION_PATTERN = "/:(?<input>\w+)/";
// Outputs
const OUTPUT_RESULT = "result";
@@ -60,15 +61,22 @@ class ExpressionFormBlock extends AbstractFormBlock
if(!$oInput->HasEventValue($sEventType)){
throw new FormsException('Unable to compute expression: input '.$aMatches['input'].' has no value for event '.$sEventType.'.');
}
return $oInput->GetValue($sEventType);
$value = $oInput->GetValue($sEventType);
if (is_string($value)) {
$value = "'$value'";
}
return $value;
},
$sExpression);
$result = '';
eval('$result = '.$sValue.';');
$this->GetOutput(self::OUTPUT_RESULT)->SetValue($sEventType, new BooleanIOFormat($result));
$this->GetOutput(self::OUTPUT_RESULT_INVERT)->SetValue($sEventType, new BooleanIOFormat(!$result));
try {
eval('$result = '.$sValue.';');
} catch (Throwable $e) {
IssueLog::Exception(__METHOD__.' expression '.json_encode($sValue).' failed with exception: '.$e->getMessage(), $e);
}
$this->GetOutput(self::OUTPUT_RESULT)->SetValue($sEventType, new BooleanIOFormat(boolval($result)));
$this->GetOutput(self::OUTPUT_RESULT_INVERT)->SetValue($sEventType, new BooleanIOFormat(!boolval($result)));
$this->GetOutput(self::OUTPUT_VALUE)->SetValue($sEventType, new RawFormat($result));
}
catch(\Exception $e){