So I have a form that is created in it's own class:
<?php
// src/AppBundle/Form/Type/CoffeeShopForm.php
namespace AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
...
class CoffeeShopType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class)
...
->add('save', SubmitType::class, array('label' => 'Create a coffee shop'))
->getForm();
;
}
}
And then I am using it in one controller
/**
* @Route("/admin/edit/{coffee_shop_id}")
*/
public function editCoffeeShopAction(Request $request, $coffee_shop_id)
{
$repository = $this->getDoctrine()->getRepository('AppBundle:CoffeeShop');
$coffeeshop = $repository->find($coffee_shop_id);
$form = $this->createForm(CoffeeShopType::class, $coffeeshop);
$form->get('name')->setData('New name value');
$form->handleRequest($request);
return $this->render('AppBundle:CoffeeController:edit_coffee_shop.html.twig', array(
'form' => $form->createView(),
));
}
So in the controller as you may see I am able to change the value of the name field with $form->get('name')->setData('New name value'); My question is how may I change the label of the SubmitType field - I searched for the documentation of this thing but I can't find it, and it is really helpful if I could reuse this form since I am using it for the add form and then for the edit form and basically it is possible in Zend Framework, so I think it should be possible also in Symfony
I have stumbled across the same question, and after extensive debugging, I can say with some confidence that what you want to do is not possible, at least in Symfony 2.8 .
However, what you can do is setting another label when rendering the form:
{{ form_row(form.name, { 'label': 'Test 123'}) }}
See http://symfony.com/doc/current/reference/forms/types/text.html#label for details.