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

Unable to load the "Symfony\Component\Form\FormRenderer" runtime issue #59

Closed
dudematthew opened this issue Dec 27, 2020 · 7 comments · Fixed by #60
Closed

Unable to load the "Symfony\Component\Form\FormRenderer" runtime issue #59

dudematthew opened this issue Dec 27, 2020 · 7 comments · Fixed by #60
Assignees
Labels

Comments

@dudematthew
Copy link

dudematthew commented Dec 27, 2020

Hello,

I encountered an issue when:

Tried to use csrf validation in symfony with pug-php

Pug-Symfony version: 3.1

PHP version: 7.2.14

I expected to get:

Normal and working login validation

But I actually get:

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

Steps to reproduce:

  • install newest symfony
  • install newest pug-php
  • some addons like Route
  • make user entity with php bin/console make:user
  • make auth controller with php bin/console make:auth, with Login form authenticator style choosed
  • convert manually login.html.twig to login.pug

This is code from login.pug:

extends ../base.pug

block 
	title Login in!

block body
	form(method="post")
		if error
			if error.messageKey !== undefined
				div.alert.alert-danger #{error.messageKey}
			else
				div.alert.alert-danger #{trans(error.messageData, 'security')}

		if app.user
			div.mb-3 You are logged in as #{ app.user.username },
				a(href=path('app_logout')) Log Out

		h1.h3.mb-3.font-weight-normal Please sign in
		label(for="inputUsername") Username
		input#inputUsername.form-control(type="text", value=last_username, name="username", required, autofocus)
		label(for="inputPassword") Password
		input#inputPassword.form-control(type="password", name="password", required)

		div.alert.alert-danger 

		.checkbox.mb-3
		    label
		        input(type="checkbox", name="_remember_me")
		        |  Remember me


		button.btn.btn-lg.btn-primary(type="submit", value=csrf_token('authenticate')) Sign in

		//- See https://symfony.com/doc/current/security/remember_me.html

The line, that is causing trouble is

button.btn.btn-lg.btn-primary(type="submit", value=csrf_token('authenticate')) Sign in

When I try to use (normally working with twig) function csrf_token('authenticate') there comes given error.

Thanks!

@dudematthew
Copy link
Author

Here is a full stack trace:

Twig\Error\RuntimeError:
Unable to load the "Symfony\Component\Form\FormRenderer" runtime.

  at {{path}}:1
  at Twig\Environment->getRuntime('Symfony\\Component\\Form\\FormRenderer')
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\var\cache\dev\twig\21\216115b0d6ed449916983a6198a29297d128318c4d3e68f45aa6ffcef8316a46.php:932)
  at __TwigTemplate_89fa24c52809efe6c5b9bdc53336e5249890deff79daddb4fefe653757103d88->doDisplay(array('last_username' => 'dudematthew', 'error' => null, 'app' => object(AppVariable)), array())
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\twig\twig\src\Template.php:394)
  at Twig\Template->displayWithErrorHandling(array('last_username' => 'dudematthew', 'error' => null, 'this' => object(Environment), 'app' => object(AppVariable)), array())
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\twig\twig\src\Template.php:367)
  at Twig\Template->display(array('last_username' => 'dudematthew', 'error' => null, 'this' => object(Environment)))
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\twig\twig\src\Template.php:379)
  at Twig\Template->render(array('last_username' => 'dudematthew', 'error' => null, 'this' => object(Environment)), array())
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\twig\twig\src\TemplateWrapper.php:40)
  at Twig\TemplateWrapper->render(array('last_username' => 'dudematthew', 'error' => null, 'this' => object(Environment)))
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\twig\twig\src\Environment.php:277)
  at Twig\Environment->render('security/login.pug', array('last_username' => 'dudematthew', 'error' => null, 'this' => object(Environment)))
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\pug-php\pug-symfony\src\Pug\Twig\Environment.php:190)
  at Pug\Twig\Environment->render('security/login.pug', array('last_username' => 'dudematthew', 'error' => null, 'this' => object(Environment)))
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\symfony\framework-bundle\Controller\AbstractController.php:249)
  at Symfony\Bundle\FrameworkBundle\Controller\AbstractController->renderView('security/login.pug', array('last_username' => 'dudematthew', 'error' => null))
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\symfony\framework-bundle\Controller\AbstractController.php:257)
  at Symfony\Bundle\FrameworkBundle\Controller\AbstractController->render('security/login.pug', array('last_username' => 'dudematthew', 'error' => null))
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\src\Controller\SecurityController.php:26)
  at App\Controller\SecurityController->login(object(AuthenticationUtils))
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\symfony\http-kernel\HttpKernel.php:157)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\symfony\http-kernel\HttpKernel.php:79)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\vendor\symfony\http-kernel\Kernel.php:195)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (C:\Users\Mateusz\Documents\Developing\Projekty\RPGMusicLauncher\public\index.php:20)

@kylekatarnls
Copy link
Member

kylekatarnls commented Dec 27, 2020

I will inspect. One small thing first not related to the issue, note that title should be the name of the block (block title in both login.pug and base.pug) and it should be text only inside (if you kept the title tag in base.pug). Else here, anonymous block would have no effect.

So typical base.pug:

!!!
html
    head
        meta(charset="UTF-8")
        title
            block title.
                Welcome
        block stylesheets
    body
        block body
        block javascripts

And login.pug structure:

extends ../base

block title
    Log in!

block body
    form(method="post")
        if error
            .alert.alert-danger=error.messageKey|trans(error.messageData, 'security')

        if app.user
            .mb-3.
                You are logged in as #{ app.user.username }, #[a(href=path('app_logout')) Logout]

        h1.h3.mb-3.font-weight-normal Please sign in
        label(for="inputEmail") Email
        input(type="email" value=last_username name="email" id="inputEmail" class="form-control" required autofocus)

        label(for="inputPassword") Password
        input(type="password" name="password" id="inputPassword" class="form-control" required)

        input(type="hidden" name="_csrf_token" value=csrf_token('authenticate'))

        //- Uncomment this section and add a remember_me option below your firewall to activate remember me functionality.
        //- See https://symfony.com/doc/current/security/remember_me.html

        //- .checkbox.mb-3: label: input(type="checkbox" name="_remember_me") Remember me

        button.btn.btn-lg.btn-primary(type="submit") Sign in

@kylekatarnls kylekatarnls self-assigned this Dec 27, 2020
@kylekatarnls
Copy link
Member

I could reproduce, I will see if something changed in the FormRenderer.

@kylekatarnls
Copy link
Member

This is likely due to changes in Twig services keys, the fix for FormRenderer is ready. I will keep this open to check if other components may be impacted.

@kylekatarnls
Copy link
Member

The version 3.1.1 properly render csrf_token('authenticate') and form_* Twig functions.

@dudematthew
Copy link
Author

Perfect support - error doesn't occur anymore.
Thank you very much, also thanks for advice :)

Cheers

@kylekatarnls
Copy link
Member

I had no other runtime problem until now with latest version, so I close this.

Hope you enjoy pug-symfony in your project :)

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

Successfully merging a pull request may close this issue.

2 participants