https://github.com/steevanb/symfony-form-options-builder
FormType::buildForm() with objects instead of array.
https://github.com/steevanb/symfony-form-options-builder
formtype php symfony
Last synced: 4 months ago
JSON representation
FormType::buildForm() with objects instead of array.
- Host: GitHub
- URL: https://github.com/steevanb/symfony-form-options-builder
- Owner: steevanb
- License: apache-2.0
- Created: 2015-06-16T17:54:59.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-05-09T08:44:06.000Z (about 1 year ago)
- Last Synced: 2025-02-27T15:38:08.649Z (4 months ago)
- Topics: formtype, php, symfony
- Language: PHP
- Homepage:
- Size: 263 KB
- Stars: 0
- Watchers: 3
- Forks: 3
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/steevanb/symfony-form-options-builder/tree/5.0.0)
[](https://php.net)
[](https://symfony.com)


[](https://scrutinizer-ci.com/g/steevanb/symfony-form-options-builder/)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.[Installation](documentation/installation.md)
[Changelog](changelog.md)
Object-oriented FormType
------------------------FormType::buildForm() object oriented instead of array
Example:
```php
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('[email protected]')
->setTrim(false)
->asVariadic('field_email')
);
}
}
```[More documentation](documentation/optionsbuilder.md)
BlockPrefixTrait
----------------Add getBlockPrefix(), to always return same syntax for form type getBlockPrefix() method: form_type_formtypeclassname
Example:
```php
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;
}
```