PHP code example of gupalo / symfony-form-transformers

1. Go to this page and download the library: Download gupalo/symfony-form-transformers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gupalo / symfony-form-transformers example snippets


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);
    }