Skip to content

Commit

Permalink
Add block prefix to csrf token field
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored and fabpot committed Jan 16, 2019
1 parent 6ca3974 commit 02bd689
Showing 1 changed file with 6 additions and 5 deletions.
Expand Up @@ -90,9 +90,10 @@ public function finishView(FormView $view, FormInterface $form, array $options)
$tokenId = $options['csrf_token_id'] ?: ($form->getName() ?: \get_class($form->getConfig()->getType()->getInnerType()));
$data = (string) $options['csrf_token_manager']->getToken($tokenId);

$csrfForm = $factory->createNamed($options['csrf_field_name'], 'Symfony\Component\Form\Extension\Core\Type\HiddenType', $data, array(
$csrfForm = $factory->createNamed($options['csrf_field_name'], 'Symfony\Component\Form\Extension\Core\Type\HiddenType', $data, [
'block_prefix' => 'csrf_token',
'mapped' => false,
));
]);

$view->children[$options['csrf_field_name']] = $csrfForm->createView($view);
}
Expand All @@ -103,20 +104,20 @@ public function finishView(FormView $view, FormInterface $form, array $options)
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
$resolver->setDefaults([
'csrf_protection' => $this->defaultEnabled,
'csrf_field_name' => $this->defaultFieldName,
'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.',
'csrf_token_manager' => $this->defaultTokenManager,
'csrf_token_id' => null,
));
]);
}

/**
* {@inheritdoc}
*/
public static function getExtendedTypes(): iterable
{
return array(FormType::class);
return [FormType::class];
}
}

0 comments on commit 02bd689

Please sign in to comment.