How to customize Symfony CRUD generated form?

Asked

Viewed 834 times

1

I’m changing the Symfony template so that CRUD already has the format I need, I was able to change almost everything, but now I had the need to change the form, to edit the css classes and other elements with div and etc... to be according to the layout I want, Twig controllers and views (Edit.html.Twig.Twig, index.html.Twig, new.html.Twig, show.html.Twig.Twig and including actions.html.Twig.Twig and record_actions.html.Twig) are ok, but to make the form I see that there are calls in Twig code for a form function. I would like to know where I can change the template of this form, because I want to change its layout. Below is an excerpt from the code of the new.html.Twig.Twig.

{% block extends %}
    {{ "{% extends '::form.html.twig' %}" }} {% endblock extends %} {% block body %}
    {{ "{% block body -%}" }}
    <div class="content-wrapper-panel">
        <div class="panel form-horizontal">
            <div class="panel-heading">
                <span class="panel-title">{{ entity }} creation</span>
            </div>
            <div class="panel-body">
                {{ '{{ form(form) }}' }}
            </div>
            <div class="panel-footer">
                {% set hide_edit, hide_delete = true, true %}
                {% include 'crud/views/others/record_actions.html.twig.twig' %}
            </div>
        </div>
    </div>
    {{ "{% endblock %}" }} {% endblock body %}

Where I find the template that generates the contents of {{ form(form) }} and how to customize it?

In Edit.html.Twig.Twig it creates the delete button by the following command:

{% if ('delete' in actions) and (not hide_delete) %}
        {{ '{{ form(delete_form) }}' }}
    {% endif %}

Only it adds some Divs that I want to remove, and just leave the form and button.

The Edit code snippet that generates the delete button produces the following output after rendering html:

<form name="form" method="post" action="/sbcorp/web/app_dev.php/city/2"><input type="hidden" name="_method" value="DELETE"><div id="form"><div><button type="submit" id="form_submit" name="form[submit]" class="btn btn-group">Delete</button></div><input type="hidden" id="form__token" name="form[_token]" value="cpQYW2u5jQ9eH-Ux7VOeKQMtERVno_T4h3Olshaw9js"></div></form>

I want to leave only the form, the Hidden input and the button

The place where I am modifying the view template is being shown as shown below. I’ve already changed all the crud view and crud action Skeleton

inserir a descrição da imagem aqui

  • I don’t recommend changing the base of the system. I believe I have a way to extend in macro form these functions, as in the framework Laravel, for example. If you update the dependencies (Composer update) all these changes will be lost or who knows, until they have to be adjusted too.

  • @Lucas his suggestion is valid, had thought about this problem, the point was that I could not find another solution at first and needed to create a prototype, the links I found on the internet led me initially to this solution, but I’m open to any suggestion to improve that. Even because, really, if I have to update the component my implementation goes to space, however at first (while I do not have a better solution) is an acceptable risk and as I am still learning to move, the knowledge here will also be validated.

1 answer

3


  • I will read again and test, know if it is possible to work with Skeleton in the same way, playing to a folder and sending fetch the model in it?

  • Yes, that’s exactly the idea. I’ve done a lot of this by adapting templates to Twitter Bootstrap.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.