EWZRecaptchaBundle icon indicating copy to clipboard operation
EWZRecaptchaBundle copied to clipboard

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

Open cloudislam opened this issue 5 years ago • 4 comments

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 avatar Oct 20 '19 11:10 cloudislam

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 avatar Jan 14 '20 17:01 PWalkow

@https://github.com/prugala/PRRecaptchaBundle/issues/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

PWalkow avatar Jan 15 '20 11:01 PWalkow

@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],

icedevelopment avatar Apr 14 '22 07:04 icedevelopment

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'] %}

Erimen avatar Jun 22 '23 14:06 Erimen