mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 00:58:48 +02:00
N°8772 - Expressions inputs are now :input instead of [[input]] (and quotes are added automatically)
This commit is contained in:
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user