gupalo / symfony-form-transformers
Symfony Form Transformers
Installs: 6 107
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- symfony/form: ^6.1|^7.0
- symfony/yaml: ^6.1|^7.0
Requires (Dev)
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^10.5
README
Symfony Forms TsvTransformer
How to Install
Install the gupalo/symfony-form-transformers
package using composer:
composer require gupalo/symfony-form-transformers
Transformers
EmptyStringTransformer
: allows user to pass empty fields which should be empty strings instead of nullJsonYamlTransformer
: user views and edits field as YAML but it is stored as JSON in DB and is array in PHPStringArrayTransformer
: user can enter several strings each from new line and they will become an arrayTsvTransformer
: user copy-pastes from spreadsheet and PHP gets array with named keys (multiline and quoting are not supported)
Basic Usage
Add transformers to your forms
class YourEntity { private ?array $data = []; } /// class YourEntityType extends AbstractType { public function __construct(private JsonYamlTransformer $jsonYamlTransformer) { $this->jsonYamlTransformer = $jsonYamlTransformer; } public function buildForm(FormBuilderInterface $builder, array $options): void { $builder // ... ->add('data', TextareaType::class); $builder->get('data')->addModelTransformer($this->jsonYamlTransformer); }
Advanced Usage
Some transformers have options on construct. Options are public properties, you can change them later.
See tests
for more examples. Also look at src
- the logic is quite simple.
If you have multiline input Tsv, set TsvHelper::$multiline = true;