FriendsOfSymfony / FOSUserBundle

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages.
https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
MIT License
3.24k stars 1.57k forks source link

translation #893

Closed alexandre-melard closed 11 years ago

alexandre-melard commented 11 years ago

Hi,

My question could seem a little candid, but I am wondering why all my forms get translated except for the form legend.

Fos user change password form
Mot de passe actuel :
Nouveau mot de passe :
Vérification :

see source:

<form action="/profile/change-password" method="POST" class="fos_user_change_password">
    <fieldset><legend>Fos user change password form</legend><div id="fos_user_change_password_form_current_password_control_group" class=" control-group"><label for="fos_user_change_password_form_current_password" class=" control-label required">
    Mot de passe actuel :

            </label><div class=" controls"><input type="password" id="fos_user_change_password_form_current_password" name="fos_user_change_password_form[current_password]" required="required" class=" not-removable"></div></div><div id="fos_user_change_password_form_new_first_control_group" class=" control-group"><label for="fos_user_change_password_form_new_first" class=" control-label required">
    Nouveau mot de passe :

            </label><div class=" controls"><input type="password" id="fos_user_change_password_form_new_first" name="fos_user_change_password_form[new][first]" required="required" class=" not-removable"></div></div><div id="fos_user_change_password_form_new_second_control_group" class=" control-group"><label for="fos_user_change_password_form_new_second" class=" control-label required">
    Vérification :

            </label><div class=" controls"><input type="password" id="fos_user_change_password_form_new_second" name="fos_user_change_password_form[new][second]" required="required" class=" not-removable"></div></div><input type="hidden" id="fos_user_change_password_form__token" name="fos_user_change_password_form[_token]" class=" not-removable" value="109b97f130dfaaf11c4f3b95c227dd8736d02653"></fieldset>
    <div>
        <input type="submit" value="Modifier le mot de passe">
    </div>
</form>

Twig template:

{% extends "UcsEventFlowAnalyser::layout.html.twig" %}

{% block article %}
    {% block fos_user_content %}{% endblock %}
{% endblock %}

source: https://github.com/mylen/EventFlowAnalyser/blob/master/app/Resources/FOSUserBundle/views/layout.html.twig

I have been looking around for one hour before asking... I found that: https://github.com/phiamo/MopaBootstrapBundle/issues/275

But I would love not to extends all your nice forms :8ball:

stof commented 11 years ago

We don't have any legend in the bundle. So it looks like you are already doing some custom rendering.

alexandre-melard commented 11 years ago

J'ai remarqué que le seul formulaire où il n'y avait pas cette balise legend était celui du login, or lorsque je regarde les vues twig, tu écrit completement le formulaire alors que pour les autres il est obtenu à partir d'un {{ form_widget(form) }}

stof commented 11 years ago

this looks like an issue cause by a custom them you are using

alexandre-melard commented 11 years ago

Sorry, I'm tired, I was writing in French...

the only difference I see is that you don't build the Form in the same way in the login window

<form action="{{ path("fos_user_security_check") }}" method="post">
    <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

    <label for="username">{{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label>
    <input type="text" id="username" name="_username" value="{{ last_username }}" required="required" />

    <label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label>
    <input type="password" id="password" name="_password" required="required" />

    <input type="checkbox" id="remember_me" name="_remember_me" value="on" />
    <label for="remember_me">{{ 'security.login.remember_me'|trans({}, 'FOSUserBundle') }}</label>

    <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}" />
</form>

and in the other formas:

<form action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit">
    {{ form_widget(form) }}
    <div>
        <input type="submit" value="{{ 'profile.edit.submit'|trans({}, 'FOSUserBundle') }}" />
    </div>
</form>

For example, so I was wondering if it wasn't the form builder that was messing up

alexandre-melard commented 11 years ago

I'm looking everywhere, I post as soon as I find it..

alexandre-melard commented 11 years ago

Ok, it's definitly added with the {{ form_widget(form) }} so I will give a look in the form factory..

stof commented 11 years ago

@mylen Are you using a custom form theme or custom form extensions ? This form legend is not added by this bundle and does not appear when using it with the core Symfony theme

alexandre-melard commented 11 years ago

Ok, I think I found it..

I am using as you do a Form Type:

https://github.com/mylen/EventFlowAnalyser/blob/master/src/Atos/Worldline/Fm/Integration/Ucs/EventFlowAnalyser/Form/ProjectType.php

in this code, there is a getName function:

    public function getName()
    {
        return 'project';
    }

I tried to play with the name, it is this name that is output as legend when the {{ form_widget(form) }} is rendered by the form factory:

namespace Symfony\Component\Form;

use Symfony\Component\Form\Exception\UnexpectedTypeException;

class FormFactory implements FormFactoryInterface
{

//...

    /**
     * {@inheritdoc}
     */
    public function createBuilder($type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null)
    {
        $name = $type instanceof FormTypeInterface || $type instanceof ResolvedFormTypeInterface
            ? $type->getName()
            : $type;

        return $this->createNamedBuilder($name, $type, $data, $options, $parent);
    }
//...

Now your telling me that the rendering might be corrupted by a plugin I installed... I will look further to that tag

alexandre-melard commented 11 years ago

Ok, I found it!!

I am using MopaBootstrapBundle that defines an extension for form with a legend tag! https://github.com/mylen/MopaBootstrapBundle/blob/master/Form/Extension/LegendFormTypeExtension.php

It's a lot like looking for a needle in a haystack :8ball:

I would like to thank you for your time (it's not the first time..)

Now I have to see who I can disable this for your bundle..

alexandre-melard commented 11 years ago

Just in case someone is having the same problem.. Add this to your conf:

mopa_bootstrap:
    form:
        show_legend: false # default is true

But I still have to find out how I can configure that just for the FOS bundle... I let you know when I find out..

sstok commented 11 years ago

Overwrite/extend the FOSUserBundle Views and set a custom Form theme where legend is disabled.