如何将Symfony表单类型属性与来自form_row的属性合并到twig中

Suppose we have Symfony form type and a row adding field

$builder->add('name', 'text', ['attr' => ['class' => 'firstName', placeholder => 'first name']]);

I want this to be merged with attributes set in twig template:

{{ form_row(form.name, {'attr':{'class':'newClass'}}) }}

Currently it does replace. What is the best way to solve it?

You can use form variables to get form class attr, then concatene another class attr:

{{ form_row(form.name, {'attr':{'class':'newClass ' ~ form.name.vars.attr.class|default('')}}) }}

EDIT:

Corrected my previous answer after reading https://symfony.com/doc/current/reference/forms/twig_reference.html#reference-form-twig-variables