Lepiej jest nadać atrybuty dla pól korzystając z komponentu Form:
$builder->add('username', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'placeholder' => 'Username',
'class' => 'btn',
]
]);
Czy jednak zrobić to w warstwie widoku - czyli wtedy dodać to pole w taki sposób:
$builder->add('username', TextType::class);
I w szablonie Twig wyświetlić go w taki sposób:
{{ form_label(form.username, 'Whatever...') }}
{{ form_widget(form.username, {'attr': {'placeholder': 'Username', 'class': 'btn'}}) }}
W dokumentacji napisali odnośnie nadawania atrybutów za pomocą komponentu Form:
This is also an important error, because you are mixing presentation markup (labels, CSS classes, etc.) with pure PHP code. Separation of concerns is always a good practice to follow, so put all the view-related things in the view layer:
Ale widzę, że często sami te atrybuty nadają w klasach pokroju FormType.
Tutaj cały przykład: https://symfony.com/doc/current/best_practices/forms.html#form-button-configuration
Który sposób jest prawidłowy?