Manipulate form.

0.0.0 2023-03-11 15:08 UTC

This package is auto-updated.

Last update: 2024-12-01 00:09:16 UTC


README

This library helps manipulating forms.

Installation

Use Composer to install the package:

composer require atournayre/form

Features

  • Add a maxlength attribute to all text fields

Example

namespace App\Subscriber\Form;

use Atournayre\Helper\Decorator\Form\MaxLengthFormDecorator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class FormDecoratorSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            FormEvents::PRE_SET_DATA => 'onPreSetData',
        ];
    }

    public function onPreSetData(FormEvent $event)
    {
        $form = $event->getForm();
        // Add a maxlength attribute to all text fields.
        MaxLengthFormDecorator::decorate($form);
    }
}

Contribute

Contributions to the package are always welcome!

License

All contents of this package are licensed under the MIT license.