2
votes

I know this subject is already open, but after few month theire is no answer at all, and when i tried answer to know if this author got any solutions ... My comment was deleted. So i'm theire to post again this problem.

I'm using for my administration SonataAdminBunbdle and SonataUserBundle. Everything is working almost fine, beside few specific things.

Now, my problem. I wanna override the default login form. But, even everything i tried, nothing works.

1) I tryed to override the FOSUserBundle login form like said in official documentation.

I put in correct path this file

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

{% block fos_user_content %}
    AZERTY
{% endblock fos_user_content %}

Deleted completely the original login form, but nothing change i still have the same default login form.

2) using the same method for SonataAdminBundle but theire's nothing for login form templates.

3) Then again one time for SonataUserBundle but i didn't find anything to override the login form template.

I'm out of solutions, that's why i'm theire to asking help. I find how to change the login form by going directly modify my vendor's files:

// vendor/sonata-project/user-bundle/Resources/views/Admin/Security/login.html.twig    

{% extends base_template %}

{% block content %}
    <div class="connection">
        <form action="{{ path("sonata_user_admin_security_check") }}" method="post">

            {% if error %}
                <div class="alert alert-error">{{ error|trans({}, 'SonataUserBundle') }}</div>
            {% endif %}

            <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

            <div class="control-group">
                <label for="username">{{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label>

                <div class="controls">
                    <input type="text" id="username" name="_username" value="{{ last_username }}" class="big sonata-medium"/>
                </div>
            </div>

            <div class="control-group">
                <label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label>

                <div class="controls">
                    <input type="password" id="password" name="_password" class="big sonata-medium" />
                </div>
            </div>

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

            <div class="form-actions">
                <input type="submit" class="btn btn-primary" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}" />
            </div>
        </form>
    </div>
{% endblock content %}

So, finally i wanna override this specific file, or find a way to change the template path in a configuration file.

Anyone has already override this login form template ?

2
Have you tried to create a corresponding view folder in app > resources ? Like : app > Resources > sonata-project > user-bundle > Resources > views > Admin > Security > login.html.twig Don't forget to clear cache. Not really like that of course, more like SonaUserBundle > etc but I did not need to do this recently - Delphine
Thx for your answer @Delphine, i tried almost all combinaisons i can imagine - app > Resources > AdminUserBundle > Resources > views > Admin > Security - app > Resources > SonataUserBundle > Resources > views > Admin - app > Resources > sonata-project > user-bundle > Resources > views > Security - app > Resources > views > AdminUserBundle > Resources > views > Admin > Security - app > Resources > views > SonataUserBundle > Resources > views > Admin > Security Nothing changed, still all the time the same default login form - Allchimiste

2 Answers

10
votes

If you place your custom login.html.twig into:

app/Resources/SonataUserBundle/views/Admin/Security

it will work.

You can read more about overriding templates in Symfony.

1
votes

1/ Ok ! I know you made several searches but have you tried this :

Resources/
├── ApplicationSonataUserBundle
│   └── views
│       | 
│       └── Security
│           └── login.html.twig

According to your comment, I don't see this solution.

UPDATE :

ApplicationSonataUserBundle is an extend. I use to do that with SonataMediaBundle.

For example, in ApplicationSonataMediaBundle.php :

class ApplicationSonataMediaBundle extends Bundle
{
    /**
     * {@inheritdoc}
     */
    public function getParent()
    {
        return 'SonataMediaBundle';
    }
}