steevanb / sf2-form-utils
This package is abandoned and no longer maintained.
The author suggests using the steevanb/symfony-form-options-builder package instead.
buildForm() with objects instead of array
5.1.0
2024-05-09 08:43 UTC
Requires
- php: ^7.1||^8.0
- symfony/form: ^3.0||^4.0||^5.0||^6.0||^7.0
Requires (Dev)
- doctrine/orm: ^2.8
- symfony/doctrine-bridge: ^6.3
- symfony/security-csrf: ^6.3
This package is auto-updated.
Last update: 2024-05-09 08:44:09 UTC
README
symfony-form-options-builder
It helps you writing your Symfony FormType, with some traits and methods to add fields in buildForm() instead of array with some mysterious keys, and other stuff.
Object-oriented FormType
FormType::buildForm() object oriented instead of array
Example:
namespace FooBundle\Form\Type; use Steevanb\SymfonyFormOptionsBuilder\OptionsBuilder\EmailOptionsBuilder; use Steevanb\SymfonyFormOptionsBuilder\OptionsBuilder\TextOptionsBuilder; use Symfony\Component\Form\Extension\Core\Type\TextType; class BarType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { # Since PHP 5.5, you can use FooClass::class $builder->add('field_text', TextType::class, TextOptionsBuilder::create()->asArray()); # Since PHP 5.6, you can use the variadic syntax. asVariadic() parameter is field name. $builder->add( ...EmailOptionsBuilder::create() ->setRequired(false) ->setPlaceHolder('default@mail.com') ->setTrim(false) ->asVariadic('field_email') ); } }
BlockPrefixTrait
Add getBlockPrefix(), to always return same syntax for form type getBlockPrefix() method: form_type_formtypeclassname
Example:
namespace FooBundle\Form\Type; use Steevanb\SymfonyFormOptionsBuilder\BlockPrefixTrait; class BarType extends AbstractType { # Use this trait to define getBlockPrefix() required method. It will return form_type_bar use BlockPrefixTrait; }