N°8772 - Form dependencies manager implementation

- Form SDK implementation
- Basic Forms
- Dynamics Forms
- Basic Blocks + Data Model Block
- Form Compilation
- Turbo integration
This commit is contained in:
Benjamin Dalsass
2025-12-30 11:42:55 +01:00
committed by GitHub
parent 3955b4eb22
commit 4c1ad0f4f2
813 changed files with 115243 additions and 489 deletions

View File

@@ -0,0 +1,62 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Forms\Block\Expression;
use Combodo\iTop\Forms\Block\AbstractFormBlock;
use Combodo\iTop\Forms\Block\FormBlockException;
use Combodo\iTop\Forms\IO\Format\BooleanIOFormat;
use Combodo\iTop\Forms\Register\IORegister;
use Exception;
use Expression;
use Symfony\Component\Form\FormEvents;
/**
* An abstract block to manage an expression.
*
* @package Combodo\iTop\Forms\Block\Expression
* @since 3.3.0
*/
abstract class AbstractExpressionFormBlock extends AbstractFormBlock
{
public const EXPRESSION_PATTERN = "/:(?<input>\w+)/";
/** @inheritdoc
* @throws FormBlockException
*/
public function AllInputsReadyEvent(): void
{
parent::AllInputsReadyEvent();
$this->ComputeExpression(FormEvents::POST_SET_DATA);
$this->ComputeExpression(FormEvents::POST_SUBMIT);
}
/**
* Compute the expression and set the output values.
*
* @param string $sEventType
*
* @return mixed
* @throws FormBlockException
*/
public function ComputeExpression(string $sEventType): mixed
{
$sExpression = $this->GetOption('expression');
try {
$oExpression = Expression::FromOQL($sExpression);
$aFieldsToResolve = $oExpression->ListRequiredFields();
$aResolvedParams = [];
foreach ($aFieldsToResolve as $sFieldToResolve) {
$aResolvedParams[$sFieldToResolve] = strval($this->GetInputValue($sFieldToResolve));
}
return $oExpression->Evaluate($aResolvedParams);
} catch (Exception $e) {
throw new FormBlockException('Compute expression '.json_encode($sExpression).' block issue: '.$e->getMessage(), 0, $e);
}
}
}

View File

@@ -0,0 +1,56 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Forms\Block\Expression;
use Combodo\iTop\Forms\Block\FormBlockException;
use Combodo\iTop\Forms\IO\Format\BooleanIOFormat;
use Combodo\iTop\Forms\Register\IORegister;
/**
* An abstract block to manage an expression.
* This block expose two boolean outputs: the result of the expression and its negation.
*
* @package Combodo\iTop\Forms\Block\Expression
* @since 3.3.0
*/
class BooleanExpressionFormBlock extends AbstractExpressionFormBlock
{
// Outputs
public const OUTPUT_RESULT = "result";
public const OUTPUT_NOT_RESULT = "not_result";
/** @inheritdoc */
protected function RegisterIO(IORegister $oIORegister): void
{
parent::RegisterIO($oIORegister);
$oIORegister->AddOutput(self::OUTPUT_RESULT, BooleanIOFormat::class);
$oIORegister->AddOutput(self::OUTPUT_NOT_RESULT, BooleanIOFormat::class);
}
/**
* Compute the expression and set the output values.
*
* @param string $sEventType
*
* @return mixed
* @throws \Combodo\iTop\Forms\Block\FormBlockException
* @throws \Combodo\iTop\Forms\Register\RegisterException
*/
public function ComputeExpression(string $sEventType): mixed
{
$oResult = parent::ComputeExpression($sEventType);
// Update output
$bResult = boolval($oResult);
$this->GetOutput(self::OUTPUT_RESULT)->SetValue($sEventType, new BooleanIOFormat($bResult));
$this->GetOutput(self::OUTPUT_NOT_RESULT)->SetValue($sEventType, new BooleanIOFormat(!$bResult));
return $oResult;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Forms\Block\Expression;
use Combodo\iTop\Forms\Block\FormBlockException;
use Combodo\iTop\Forms\IO\Format\NumberIOFormat;
use Combodo\iTop\Forms\Register\IORegister;
/**
* A block to manage an number expression.
* This block expose a number output: the result of the expression.
*
* @package Combodo\iTop\Forms\Block\Expression
* @since 3.3.0
*/
class NumberExpressionFormBlock extends AbstractExpressionFormBlock
{
// Outputs
public const OUTPUT_RESULT = "result";
/** @inheritdoc */
protected function RegisterIO(IORegister $oIORegister): void
{
parent::RegisterIO($oIORegister);
$oIORegister->AddOutput(self::OUTPUT_RESULT, NumberIOFormat::class);
}
/**
* Compute the expression and set the output values.
*
* @param string $sEventType
*
* @return mixed
* @throws \Combodo\iTop\Forms\Block\FormBlockException
* @throws \Combodo\iTop\Forms\Register\RegisterException
*/
public function ComputeExpression(string $sEventType): mixed
{
$oResult = parent::ComputeExpression($sEventType);
// Update output
$this->GetOutput(self::OUTPUT_RESULT)->SetValue($sEventType, new NumberIOFormat($oResult));
return $oResult;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* @copyright Copyright (C) 2010-2025 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Forms\Block\Expression;
use Combodo\iTop\Forms\IO\Format\StringIOFormat;
use Combodo\iTop\Forms\Register\IORegister;
class StringExpressionFormBlock extends AbstractExpressionFormBlock
{
// Outputs
public const OUTPUT_RESULT = 'result';
/** @inheritdoc */
protected function RegisterIO(IORegister $oIORegister): void
{
parent::RegisterIO($oIORegister);
$oIORegister->AddOutput(self::OUTPUT_RESULT, StringIOFormat::class);
}
/**
* Compute the expression and set the output values.
*
* @param string $sEventType
*
* @return mixed
* @throws \Combodo\iTop\Forms\Block\FormBlockException
* @throws \Combodo\iTop\Forms\Register\RegisterException
*/
public function ComputeExpression(string $sEventType): mixed
{
$oResult = parent::ComputeExpression($sEventType);
// Update output
$this->GetOutput(self::OUTPUT_RESULT)->SetValue($sEventType, new StringIOFormat($oResult));
return $oResult;
}
}