Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 2 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 (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-05-09T08:44:06.000Z (8 months ago)
- Last Synced: 2024-10-13T19:05:34.611Z (2 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
[![version](https://img.shields.io/badge/version-5.0.0-green.svg)](https://github.com/steevanb/symfony-form-options-builder/tree/5.0.0)
[![php](https://img.shields.io/badge/php-^7.1||^8.0-blue.svg)](https://php.net)
[![symfony](https://img.shields.io/badge/symfony/form-^3||^4||^5||^6||^7-blue.svg)](https://symfony.com)
![Lines](https://img.shields.io/badge/code%20lines-4918-green.svg)
![Total Downloads](https://poser.pugx.org/steevanb/symfony-form-options-builder/downloads)
[![Scrutinizer](https://scrutinizer-ci.com/g/steevanb/symfony-form-options-builder/badges/quality-score.png?b=master)](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;
}
```