简体   繁体   English

Sonata管理员捆绑+ Sonata用户捆绑:覆盖登录表单

[英]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. 我正在使用SonataAdminBunbdle和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 . 1)我试图覆盖FOSUserBundle登录表单,如官方文档中所述。

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. 2)对SonataAdminBundle使用相同的方法,但对于登录表单模板则一无所获。

3) Then again one time for SonataUserBundle but i didn't find anything to override the login form template. 3)然后再次为SonataUserBundle,但我没有发现任何东西可以覆盖登录表单模板。

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: 如果您将自定义的login.html.twig放入:

app/Resources/SonataUserBundle/views/Admin/Security

it will work. 它会工作。

You can read more about overriding templates in Symfony. 您可以在Symfony中阅读有关覆盖模板的更多信息。

1/ Ok ! 1 /好! 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. ApplicationSonataUserBundle是扩展。 I use to do that with SonataMediaBundle. 我曾经用SonataMediaBundle做到这一点。

For example, in ApplicationSonataMediaBundle.php : 例如,在ApplicationSonataMediaBundle.php中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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