I updated and summurized the question.
What I want to do is changing the default value of form object after getForm()
public function newAction(Request $request)
{
$task = new Task();
$form = $this->createFormBuilder($task)
->add('task', TextType::class,array('data' => 'default text data') // Set the default data for loaded first time.
->add('save', SubmitType::class, array('label' => 'Save'))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//I want change the default value of task, I tried a few methods.
$d = $form->getData();
$form->get('task')->setData('replace text data'); // not work
$d->setData('second data'); // notwork
}
Is it possible or how??