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

[Symfony 4.3.5] Twig failed to render the widget "Array to string conversion" #234

Open
cloudislam opened this issue Oct 20, 2019 · 4 comments

Comments

@cloudislam
Copy link

Hi!

I'm trying to install this bundle in Symfony 4.3.6 and I'm faced with a problem.

Twig can't render the widget and outputs the following:

An exception has been thrown during the rendering of a template ("Notice: Array to string conversion").

It looks like the issue in the form type options. The attr option contains the options key which is an array (the attr option is an associative array with HTML attributes as keys accordingly to the Symfony docs).

Please fix this issue.

@cloudislam cloudislam changed the title [Symfony 4.3.6] Twig failed to render the widget "Array to string conversion" [Symfony 4.3.5] Twig failed to render the widget "Array to string conversion" Oct 20, 2019
@PWalkow
Copy link

PWalkow commented Jan 14, 2020

Same problem here, default value for 'attr'=> 'options' is an array and symfony twig bridge is trying to display it... in form_div_layout.html.twig:451

@PWalkow
Copy link

PWalkow commented Jan 15, 2020

@prugala/PRRecaptchaBundle#22

Same issue happened on the different bundle, temporary solution is to add an entry to twig.yaml configuration under form_themes:

form_themes:
        - '@EWZRecaptcha/Form/ewz_recaptcha_widget.html.twig'

Note: ( @excelwebzone , @cloudislam )This entry should be injected automatically by EWZRecaptchaExtension but it doesn't in symfony v4.4

@icedevelopment
Copy link

@prugala/PRRecaptchaBundle#22

Same issue happened on the different bundle, temporary solution is to add an entry to twig.yaml configuration under form_themes:

form_themes:
        - '@EWZRecaptcha/Form/ewz_recaptcha_widget.html.twig'

Note: ( @excelwebzone , @cloudislam )This entry should be injected automatically by EWZRecaptchaExtension but it doesn't in symfony v4.4

This problem happens when EWZRecaptchaBundle is loaded before TwigBundle.

To fix it you simply need to edit your bundles.php and move the line
EWZ\Bundle\RecaptchaBundle\EWZRecaptchaBundle::class => ['all' => true],
after
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],

@Erimen
Copy link

Erimen commented Jun 22, 2023

Hello,

I'm facing the same error, Twig bundle is loaded before EWZ and I've added the form_theme but still not working.
I've already tried reinstalling the package, changing the order of the bundles, form_themes path with @EWZRecaptcha or %kernel.project_dir% or absolute, nothing work.

I'm using Symfony 5.4 with latest version of EWZ.

Thank you in advance

Edit: I got it to work by adding this directly in my twig template but it's not ideal
{% form_theme form with ['@EWZRecaptcha/Form/ewz_recaptcha_widget.html.twig'] %}

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

4 participants