uxf/form

Maintainers

Details

gitlab.com/uxf/form

Source

Issues

Installs: 17 627

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/uxf/form

3.74.0 2025-11-21 15:56 UTC

This package is auto-updated.

Last update: 2025-11-21 15:04:18 UTC


README

Symfony Form bundle

Install

$ composer require uxf/form

Config

// config/routes/uxf.php
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function (RoutingConfigurator $routingConfigurator): void {
    $routingConfigurator->import('@UXFFormBundle/config/routes.php');
};

Service

// config/packages/uxf.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $config): void {
    $config->extension('uxf_form', [
        'gen' => [
            'schema_with_hidden_fields' => true, // default false
            'areas' => [
                'admin' => [
                    'allowed' => '/^(admin|test)/', // optional
                    'disabled' => '/^(private|hello)/', // optional
                    'destination' => __DIR__ . '/../../../backoffice/src/generated/form-schema',
                ],
            ],
        ],
    ]);
};

Usage

OneToMany must have indexBy="id" and child entity must have property named $parent in constructor.

Events

FormEntityEditedEvent

use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use UXF\Core\Exception\BasicException;
use UXF\Form\Event\FormEntityEditedEvent;

#[AsEventListener]
final readonly class FormEntityEditedEventListener
{
    public function __invoke(FormEntityEditedEvent $event): void
    {
        // do something with $event->entity and $event->new
    }
}

FormEntityErrorEvent

use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use UXF\Core\Exception\BasicException;
use UXF\Form\Event\FormEntityErrorEvent;

#[AsEventListener]
final readonly class FormEntityErrorEventListener
{
    public function __invoke(FormEntityErrorEvent $event): void
    {
        // custom exception
        if ($event->entity instanceof Small && $event->error instanceof ORMException) {
            $event->error = BasicException::badRequest('awesome');
        }
    }
}