|
@@ -27,6 +27,12 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
|
|
$this->fieldName = $fieldName;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Adds a CSRF field to the form when the CSRF protection is enabled.
|
|
|
+ *
|
|
|
+ * @param FormBuilder $builder The form builder
|
|
|
+ * @param array $options The options
|
|
|
+ */
|
|
|
public function buildForm(FormBuilder $builder, array $options)
|
|
|
{
|
|
|
if ($options['csrf_protection']) {
|
|
@@ -36,11 +42,19 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
|
|
$csrfOptions['csrf_provider'] = $options['csrf_provider'];
|
|
|
}
|
|
|
|
|
|
- $builder->add($options['csrf_field_name'], 'csrf', $csrfOptions)
|
|
|
- ->setAttribute('csrf_field_name', $options['csrf_field_name']);
|
|
|
+ $builder
|
|
|
+ ->add($options['csrf_field_name'], 'csrf', $csrfOptions)
|
|
|
+ ->setAttribute('csrf_field_name', $options['csrf_field_name'])
|
|
|
+ ;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Removes CSRF fields from all the form views except the root one.
|
|
|
+ *
|
|
|
+ * @param FormView $view The form view
|
|
|
+ * @param FormInterface $form The form
|
|
|
+ */
|
|
|
public function buildViewBottomUp(FormView $view, FormInterface $form)
|
|
|
{
|
|
|
if ($view->hasParent() && $form->hasAttribute('csrf_field_name')) {
|
|
@@ -52,16 +66,22 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
public function getDefaultOptions(array $options)
|
|
|
{
|
|
|
return array(
|
|
|
- 'csrf_protection' => $this->enabled,
|
|
|
- 'csrf_field_name' => $this->fieldName,
|
|
|
- 'csrf_provider' => null,
|
|
|
- 'intention' => 'unknown',
|
|
|
+ 'csrf_protection' => $this->enabled,
|
|
|
+ 'csrf_field_name' => $this->fieldName,
|
|
|
+ 'csrf_provider' => null,
|
|
|
+ 'intention' => 'unknown',
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
public function getExtendedType()
|
|
|
{
|
|
|
return 'form';
|