1. Go to this page and download the library: Download wemxo/dynamic-form-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Wemxo\DynamicFormBundle\Form\DynamicType;
use Wemxo\DynamicFormBundle\Utils\Helper\DynamicFormHelper;
class AppController extends AbstractController
{
#[Route(name: 'app_home')]
public function home(FormFactoryInterface $formFactory): Response
{
$user = $this->getUser();
$countryLabel = $user->getCountry()->getLabel();
$form = $formFactory->create(DynamicType::class, null, [
'dynamic_key' => DynamicFormHelper::configKey('address', $countryLabel),
]);
return $this->render('app/home.html.twig', [
'form' => $form->createView()
]);
}
}
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Wemxo\DynamicFormBundle\Form\DynamicType;
use Wemxo\DynamicFormBundle\Utils\Helper\DynamicFormHelper;
class AppController extends AbstractController
{
#[Route(name: 'app_home')]
public function home(FormFactoryInterface $formFactory): Response
{
$user = $this->getUser();
$countryLabel = $user->getCountry()->getLabel();
$form = $formFactory->createNamed('my_custom_prefix', DynamicType::class, null, [
'dynamic_key' => DynamicFormHelper::configKey('address', $countryLabel),
]);
return $this->render('app/home.html.twig', [
'form' => $form->createView()
]);
}
}
declare(strict_types=1);
namespace App\Form;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Wemxo\DynamicFormBundle\EventSubscriber\DynamicFormEventSubscriber;
class AddressFormEventSubscriber implements DynamicFormEventSubscriber
{
public function getName(): string
{
return 'address_event_subscriber';
}
public static function getSubscribedEvents(): array
{
return [
FormEvents::PRE_SET_DATA => 'onPreSetData',
];
}
public function onPreSetData(FormEvent $event): void
{
// do something.
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.