简体   繁体   中英

Sonata Admin Bundle + Sonata User Bundle : Override Login Form

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 ?

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/ 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';
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM