sdespont za odpowiedź jest poprawna odpowiedź i godne są wybrane. Rozszerzyłem jednak jego funkcjonalność, dodając niestandardową ikonę klasy fa, a także ikonę umieszczoną po lewej lub prawej stronie tekstu przycisku.
Ponieważ ta funkcja akceptuje zmienne, najlepszą rzeczą do zrobienia jest utworzenie szablonu do ponownego użycia zamiast dostosowywania samego widoku.
Formularz szablon: app/Resources/views/form/submit.html.twig
{# app/Resources/views/form/submit.html.twig #}
{% block submit_widget %}
{% set type = type|default('submit') %}
{% if label is empty %}
{% if label_format is not empty %}
{% set label = label_format|replace({
'%name%' : name,
'%id%' : id,
}) %}
{% else %}
{% set label = name|humanize %}
{% endif %}
{% endif %}
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>
{% if fa is defined %}
{% if left is defined and left %}
<i class="fa {{ fa }}"></i>
{% endif %}
{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}
{% if right is defined and right %}
<i class="fa {{ fa }}"></i>
{% endif %}
{% else %}
{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}
{% endif %}
</button>
{% endblock submit_widget %}
Kontroler:
$form = $this->createFormBuilder($user)
...
->add('submit', SubmitType::class, array(
'attr'=> array('class'=>'myclass')
))
->getForm();
Gałązka szablon:
{{ form_widget(form.submit, {'fa' : 'fa-long-arrow-right','right' : true}) }}
Można ustawić dowolny stara ikona i nawet rozmiar: fa-long-arrow-right fa-2x
@Raphael_b Wszelkie opinie będą mile widziane – sdespont
twój wpis jest wspaniały; Nadal muszę trochę popracować, aby w pełni go opanować. Wielkie dzięki; przepraszam za spóźnioną odpowiedź, byłem na jeden dzień. –