N°7063 - Forms SDK - Add Symfony forms component

add select
This commit is contained in:
Benjamin Dalsass
2023-12-19 11:28:17 +01:00
parent 12f3e5ed4c
commit 68b7e9ee65
9 changed files with 75 additions and 3 deletions

View File

@@ -402,6 +402,7 @@ return array(
'Combodo\\iTop\\FormSDK\\Controller\\TestController' => $baseDir . '/sources/FormSDK/Controller/TestController.php',
'Combodo\\iTop\\FormSDK\\Field\\Description\\FormFieldDescription' => $baseDir . '/sources/FormSDK/Field/Description/FormFieldDescription.php',
'Combodo\\iTop\\FormSDK\\Field\\Description\\FormFieldTypeEnumeration' => $baseDir . '/sources/FormSDK/Field/Description/FormFieldTypeEnumeration.php',
'Combodo\\iTop\\FormSDK\\Helper\\SelectHelper' => $baseDir . '/sources/FormSDK/Helper/SelectHelper.php',
'Combodo\\iTop\\FormSDK\\Service\\FactoryPlugin\\FormFactoryObjectPlugin' => $baseDir . '/sources/FormSDK/Service/FactoryPlugin/FormFactoryObjectPlugin.php',
'Combodo\\iTop\\FormSDK\\Service\\FactoryPlugin\\FormFactoryPluginInterface' => $baseDir . '/sources/FormSDK/Service/FactoryPlugin/FormFactoryPluginInterface.php',
'Combodo\\iTop\\FormSDK\\Service\\FormFactory' => $baseDir . '/sources/FormSDK/Service/FormFactory.php',

View File

@@ -801,6 +801,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
'Combodo\\iTop\\FormSDK\\Controller\\TestController' => __DIR__ . '/../..' . '/sources/FormSDK/Controller/TestController.php',
'Combodo\\iTop\\FormSDK\\Field\\Description\\FormFieldDescription' => __DIR__ . '/../..' . '/sources/FormSDK/Field/Description/FormFieldDescription.php',
'Combodo\\iTop\\FormSDK\\Field\\Description\\FormFieldTypeEnumeration' => __DIR__ . '/../..' . '/sources/FormSDK/Field/Description/FormFieldTypeEnumeration.php',
'Combodo\\iTop\\FormSDK\\Helper\\SelectHelper' => __DIR__ . '/../..' . '/sources/FormSDK/Helper/SelectHelper.php',
'Combodo\\iTop\\FormSDK\\Service\\FactoryPlugin\\FormFactoryObjectPlugin' => __DIR__ . '/../..' . '/sources/FormSDK/Service/FactoryPlugin/FormFactoryObjectPlugin.php',
'Combodo\\iTop\\FormSDK\\Service\\FactoryPlugin\\FormFactoryPluginInterface' => __DIR__ . '/../..' . '/sources/FormSDK/Service/FactoryPlugin/FormFactoryPluginInterface.php',
'Combodo\\iTop\\FormSDK\\Service\\FormFactory' => __DIR__ . '/../..' . '/sources/FormSDK/Service/FormFactory.php',

View File

@@ -3,7 +3,7 @@
'name' => 'combodo/itop',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '7b12398ea847dd7fb39463568c3be6849b3bd1d6',
'reference' => '12f3e5ed4ca8538b4646ca04d1d5abd7f37f3f67',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -22,7 +22,7 @@
'combodo/itop' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '7b12398ea847dd7fb39463568c3be6849b3bd1d6',
'reference' => '12f3e5ed4ca8538b4646ca04d1d5abd7f37f3f67',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),

View File

@@ -3,7 +3,9 @@
namespace Combodo\iTop\FormSDK\Controller;
use Combodo\iTop\Controller\AbstractAppController;
use Combodo\iTop\FormSDK\Helper\SelectHelper;
use Combodo\iTop\FormSDK\Service\FormManager;
use Dict;
use Exception;
use MetaModel;
use Symfony\Component\HttpFoundation\Request;
@@ -50,6 +52,7 @@ class TestController extends AbstractAppController
// others data
$oFormFactory->AddText('data1', ['label' => 'Ma ville'], 'Autun');
$oFormFactory->AddText('data2', ['label' => 'Pays'], 'FRANCE');
$oFormFactory->AddSelect('data3', ['label' => 'Language', 'choices' => SelectHelper::GetApplicationLanguages()], 'FR FR');
// get the form
$oForm = $oFormFactory->GetForm();
@@ -70,7 +73,7 @@ class TestController extends AbstractAppController
return $this->render('formSDK/form.html.twig', [
'form' => $oFormFactory->GetForm(),
'theme' => 'formSDK/theme/portal.html.twig'
'theme' => 'formSDK/themes/portal.html.twig'
]);
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* Copyright (C) 2013-2023 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\FormSDK\Helper;
use Dict;
/**
*
* @package FormSDK
* @since 3.2.0
*/
class SelectHelper
{
static public function GetApplicationLanguages() : array
{
$aAvailableLanguages = Dict::GetLanguages();
$aLanguageCodes = array();
foreach($aAvailableLanguages as $sLangCode => $aInfo){
$sLanguageLabel = $aInfo['description'].' ('.$aInfo['localized_description'].')';
$aLanguageCodes[$sLanguageLabel] = $sLangCode;
}
return $aLanguageCodes;
}
}

View File

@@ -74,6 +74,23 @@ class FormFactory
return $this;
}
/**
* Add select.
*
* @param string $sKey
* @param array $aOptions
* @param mixed $oData
*
* @return $this
*/
public function AddSelect(string $sKey, array $aOptions, mixed $oData) : FormFactory
{
$this->aDescriptions[$sKey] = new FormFieldDescription($sKey, FormFieldTypeEnumeration::SELECT, $aOptions);
$this->aData[$sKey] = $oData;
return $this;
}
/**
* @return array{descriptions:array, data:array}
*/

View File

@@ -23,6 +23,7 @@ use Combodo\iTop\FormSDK\Symfony\Type\Compound\FormObjectType;
use Combodo\iTop\FormSDK\Field\Description\FormFieldDescription;
use Combodo\iTop\FormSDK\Field\Description\FormFieldTypeEnumeration;
use LogAPI;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormFactoryInterface;
@@ -64,6 +65,13 @@ class SymfonyBridge
'options' => $oFormDescription->GetOptions()
];
case FormFieldTypeEnumeration::SELECT:
return [
'path' => $oFormDescription->GetPath(),
'type' => ChoiceType::class,
'options' => $oFormDescription->GetOptions()
];
case FormFieldTypeEnumeration::DB_OBJECT:
$aOptions = $oFormDescription->GetOptions();
$aItems = [];