Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TwigBridge] FormExtension/TwigRenderer/FormRenderer BC break on 3.4 #24533

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

Closed
dmaicher opened this issue Oct 12, 2017 · 6 comments
Closed

[TwigBridge] FormExtension/TwigRenderer/FormRenderer BC break on 3.4 #24533

dmaicher opened this issue Oct 12, 2017 · 6 comments

Comments

@dmaicher
Copy link
Contributor

dmaicher commented Oct 12, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no
Symfony version 3.4.x-dev 0f5e38c

I just tried upgrading one of my apps from 3.3.10 to symfony 3.4.x-dev and stumbled across this issue in combination with Sonata admin: sonata-project/SonataAdminBundle#4652

As far as I understand the TwigRenderer was deprecated and is now actually an instance of FormRenderer?

Which breaks code like this (which is done in a similar way on Sonata admin):

$twig = $this->get('twig');

$twig
    ->getExtension('Symfony\Bridge\Twig\Extension\FormExtension')
    ->initRuntime($twig);

$twig
    ->getExtension('Symfony\Bridge\Twig\Extension\FormExtension')
    ->renderer;

Or this:

$twig = $this->get('twig');

$twig
    ->getExtension('Symfony\Bridge\Twig\Extension\FormExtension')
    ->renderer;

$twig
    ->getExtension('Symfony\Bridge\Twig\Extension\FormExtension')
    ->initRuntime($twig);

As this check is not true anymore https://github.com/symfony/symfony/blob/3.4/src/Symfony/Bridge/Twig/Extension/FormExtension.php#L55

And this method setEnvironment does not exist on FormRenderer: https://github.com/symfony/symfony/blob/3.4/src/Symfony/Bridge/Twig/Extension/FormExtension.php#L122

@dmaicher dmaicher changed the title [Bridge][Twig] FormExtension/TwigRenderer/FormRenderer BC break on 3.4 [TwigBridge] FormExtension/TwigRenderer/FormRenderer BC break on 3.4 Oct 12, 2017
@xabbuh xabbuh added this to the 3.4 milestone Oct 12, 2017
symfony-splitter pushed a commit to symfony/twig-bridge that referenced this issue Oct 13, 2017
…enderer (dmaicher)

This PR was squashed before being merged into the 3.4 branch (closes #24535).

Discussion
----------

[TwigBridge] fix BC for FormExtension if renderer is FormRenderer

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#24533
| License       | MIT
| Doc PR        | -

This fixes some issues within FormExtension since the renderer is now a `FormRenderer`.

Commits
-------

4a2f608f1e [TwigBridge] fix BC for FormExtension if renderer is FormRenderer
fabpot added a commit that referenced this issue Oct 13, 2017
…enderer (dmaicher)

This PR was squashed before being merged into the 3.4 branch (closes #24535).

Discussion
----------

[TwigBridge] fix BC for FormExtension if renderer is FormRenderer

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24533
| License       | MIT
| Doc PR        | -

This fixes some issues within FormExtension since the renderer is now a `FormRenderer`.

Commits
-------

4a2f608 [TwigBridge] fix BC for FormExtension if renderer is FormRenderer
@fabpot fabpot closed this as completed Oct 13, 2017
@mricherzhagen
Copy link

mricherzhagen commented Dec 4, 2017

I think this BC-break was not fixed in the released 3.4 version. I'm getting a

Twig_Error_Runtime
Unable to load the "Symfony\Component\Form\FormRenderer" runtime.

After updating my dependencies.

Probably also the reason, why sonata-project/SonataAdminBundle#4762 has a separate BC-Layer-Fix?

Can we get a proper fix in 3.4.1?

EDIT: Oh, it maybe was only not fixed in silexphp/Silex#1579

@dmaicher
Copy link
Contributor Author

dmaicher commented Dec 4, 2017

@mricherzhagen I also have some concerns about that issue and am not 100% sure its fixed for all possible use cases out there.

See #24535 (comment)

If you still experience issues (not related to silex) then please open a new issue 😉

@mricherzhagen
Copy link

mricherzhagen commented Dec 5, 2017

I only use Silex at the moment, but i don't think this issue is related to silex, because @jordisala1991 had to write a fix for the SonataAdminBundle which is Symfony and not Silex.

I think the twig cache might also play some role in why this is a little weird to debug. I had to clear it manually in order to get an effect.

@sproctor
Copy link

I am still experiencing this issue with Symfony 3.4.2, but not with 3.3. I used the documentation from https://symfony.com/doc/3.4/components/form.html to create a simple test.

https://gist.github.com/sproctor/7a5d5a322cc89b6839cf4d414822c316

@dmaicher
Copy link
Contributor Author

@sproctor true! Unfortunately the documentation is outdated 😢

I will create a PR to update it accordingly.

With this it works?

$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
    \Symfony\Component\Form\FormRenderer::class => function () use ($formEngine, $csrfManager) {
        return new \Symfony\Component\Form\FormRenderer($formEngine, $csrfManager);
    },
)));

dmaicher added a commit to dmaicher/symfony-docs that referenced this issue Dec 19, 2017
Using deprecated `TwigRenderer` actually is not working correctly anymore as mentioned here symfony/symfony#24533 (comment).

This should also be merged into 4.0 and master as there the class has been removed completely.
@sproctor
Copy link

@dmaicher That did it! Thank you!

javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Jan 4, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

[Form] use FormRenderer instead of TwigRenderer

Using deprecated `TwigRenderer` actually is not working correctly anymore as mentioned here symfony/symfony#24533 (comment).

This should also be merged into 4.0 and master as there the class has been removed completely.

Commits
-------

e86433d [Form] use FormRenderer instead of TwigRenderer
Stoakes added a commit to Stoakes/form-bundle that referenced this issue Feb 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants