monsieurbiz / SyliusSettingsPlugin

Provide some custom settings to your favorite Sylius shop!
MIT License
23 stars 18 forks source link

is it possible to use entitytype #70

Closed t-n-y closed 1 month ago

t-n-y commented 5 months ago

Is it possible to use an entityType, to set a collection of other entity in the configuration ?

I am looking a way to do that but can't find any exemple

delyriand commented 5 months ago

Hi @t-n-y,

Yes, it's possible to use the EntityType::class in your form type. You just need to define a data transformer.

Example with a "Page" entity from another beautiful plugin:

$this->addWithDefaultCheckbox(
    $builder, 'page', EntityType::class, [
        'class' => Page::class,
        'choice_label' => 'title',
       // ...
    ]
);

$pageToCodeTransformer = new ReversedTransformer(new ResourceToIdentifierTransformer($this->pageRepository, 'code'));
$builder->get('page')->addModelTransformer($pageToCodeTransformer);
t-n-y commented 5 months ago

Hi @delyriand,

Thank you for the quick response. I'll try to implement that. So if i understand well, you re finally saving the code string in the text_value field ?

delyriand commented 5 months ago

@t-n-y, That's right!