Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setOptions on TwigField will remove the template #267

Open
mamazu opened this issue Oct 26, 2022 · 2 comments
Open

setOptions on TwigField will remove the template #267

mamazu opened this issue Oct 26, 2022 · 2 comments

Comments

@mamazu
Copy link
Member

mamazu commented Oct 26, 2022

The problem

The TwigField is basically just a normal field with a default template. The problem is if you want to change the options of this field it will either have to specify the template again or you will lose it.

Example

<?php

$field = TwigField::create('some_field', '@Sylius/some_template.html.twig')
    ->setOptions(['vars' => ['labels' => 'path/to/label'])
;

Will result in the options being:

[
    'vars' => ['labels' => 'path/to/label']
]

and not:

[
    'template' => '@Sylius/some_template.html.twig',
    'vars' => ['labels' => 'path/to/label']
]

Possible solution

The quick and easy answer would be to have the TwigField extend the Field and change the behavior of the setOptions function to merge with the template. This would be a big change though.

@loic425
Copy link
Member

loic425 commented Nov 1, 2022

@mamazu You're right. FYI, there is a "addOption". @lchrusciel merged too quickly the notice about this issue in the doc.
But I'm in favour of the merge options with the setOptions, that was my initial idea when implementing the grid builder. I think it'd be better for DX as we already have users who have that issue.

@mamazu
Copy link
Member Author

mamazu commented Nov 1, 2022

So extending it would be the best idea? I can make a merge request for that if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants