N°7063 - Forms SDK - Add Symfony forms component

error forms issue
This commit is contained in:
Benjamin Dalsass
2024-01-10 11:24:33 +01:00
parent 021159a2c2
commit 9dde675aef
3 changed files with 19 additions and 17 deletions

View File

@@ -11,6 +11,7 @@ use Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\RouterInterface;
@@ -22,8 +23,8 @@ class TestController extends AbstractAppController
* @throws \ArchivedObjectException
* @throws \CoreException
*/
#[Route('/formSDK/test_form/{mode}', name: 'formSDK_test_form')]
public function form(Request $oRequest, FormManager $oFormManager, RouterInterface $oRouter, int $mode): Response
#[Route('/formSDK/test_form/', name: 'formSDK_test_form')]
public function form(Request $oRequest, FormManager $oFormManager, RouterInterface $oRouter, #[MapQueryParameter] int $mode=0): Response
{
// create factory
$oFactory = FormHelper::CreateSampleFormFactory($oFormManager, $oRouter, $mode);
@@ -60,8 +61,8 @@ class TestController extends AbstractAppController
* @throws \ArchivedObjectException
* @throws \CoreException
*/
#[Route('/formSDK/test_theme/{mode}', name: 'formSDK_test_theme')]
public function theme(Request $oRequest, FormManager $oFormManager, RouterInterface $oRouter, int $mode): Response
#[Route('/formSDK/test_theme', name: 'formSDK_test_theme')]
public function theme(Request $oRequest, FormManager $oFormManager, RouterInterface $oRouter, #[MapQueryParameter] int $mode = 0): Response
{
// create factory
$oFactory = FormHelper::CreateSampleFormFactory($oFormManager, $oRouter, $mode);
@@ -76,7 +77,7 @@ class TestController extends AbstractAppController
// render view
return $this->render('formSDK/theme.html.twig', [
'name1' => 'Portail',
'name1' => 'Portal',
'name2' => 'Console',
'form1' => $oForm1->createView(),
'form2' => $oForm2->createView(),

View File

@@ -69,7 +69,7 @@ class FormHelper
'counts' => ['count1' => 10, 'count2' => 20, 'count3' => 30],
'counts2' => new CountDto(),
'interval' => ['days' => '12', 'hours' => '13', 'years' => '10', 'months' => '6', 'minutes' => '0', 'seconds' => '0', 'weeks' => '3'],
'blog' => '<h2>Your <b>story</b></h2><br>bla bla bla bla bla bla<br>bla bla bla bla bla bla<br>bla bla bla bla bla bla<br>bla bla bla bla bla bla',
'blog' => '<h2>Your <b>story</b></h2><br><b>start here</b>, bla bla bla bla bla bla<br>bla bla bla bla bla bla<br>bla bla bla bla bla bla<br>bla bla bla bla bla bla',
'notify' => true,
'language' => 'FR FR',
'mode' => '1',

View File

@@ -189,16 +189,16 @@ class SymfonyBridge
/**
* Create Symfony form.
*
* @param array $aDescriptions
* @param array $aFieldsDescriptions
* @param mixed $oData
* @param string|null $sName
* @param array $aLayout
*
* @return \Symfony\Component\Form\FormInterface
*/
public function CreateForm(array $aDescriptions, mixed $oData, ?string $sName = null, array $aLayout = []): FormInterface
public function CreateForm(array $aFieldsDescriptions, mixed $oData, ?string $sName = null, array $aLayout = []): FormInterface
{
// create Symfony form builder
// create Symfony form builder (with or without name, name is by default `form`)
if($sName !== null){
$oFormBuilder = $this->oFormFactory->createNamedBuilder($sName, FormType::class, $oData);
}
@@ -206,28 +206,29 @@ class SymfonyBridge
$oFormBuilder = $this->oFormFactory->createBuilder(FormType::class, $oData);
}
// transform fields descriptions...
// transform fields descriptions to Symfony types...
$aSymfonyTypesDeclaration = [];
foreach ($aDescriptions as $sKey => $oFormDescription){
$aSymfonyTypesDeclaration[$sKey] = $this->ToSymfonyFormType($oFormDescription);
foreach ($aFieldsDescriptions as $sKey => $oFormFieldDescription){
$aSymfonyTypesDeclaration[$sKey] = $this->ToSymfonyFormType($oFormFieldDescription);
}
// prepare fieldset types layout...
// prepare fieldset types layouts...
foreach ($aSymfonyTypesDeclaration as &$aSymfonyTypeDeclaration){
if($aSymfonyTypeDeclaration['type'] === FieldsetType::class && isset($aSymfonyTypeDeclaration['options']['layout'])){
if($aSymfonyTypeDeclaration['type'] === FieldsetType::class
&& isset($aSymfonyTypeDeclaration['options']['layout'])){
['types' => $aItems] = $this->CreateLayoutTypes($aSymfonyTypeDeclaration['options']['layout'], $oFormBuilder, $aSymfonyTypeDeclaration['options']['fields']);
$aSymfonyTypeDeclaration['options']['fields'] = array_merge($aItems, $aSymfonyTypeDeclaration['options']['fields']);
}
}
// prepare general layout types
// prepare global layout types
['types' => $aItems] = $this->CreateLayoutTypes($aLayout, $oFormBuilder, $aSymfonyTypesDeclaration);
$aSymfonyTypesDeclaration = array_merge($aItems, $aSymfonyTypesDeclaration);
// add symfony types to builder...
// add Symfony types to builder...
foreach ($aSymfonyTypesDeclaration as $oSymfonyTypeDeclaration){
// add type to form
// add Symfony type to form
$oFormBuilder->add(
$oSymfonyTypeDeclaration['name'],
$oSymfonyTypeDeclaration['type'],