[Form] Added FormBuilderInterface and FormViewInterface and cleaned up FormTypeInterface and FormTypeExtensionInterface
This commit is contained in:
parent
0ef4066983
commit
2cd99e80b6
@ -290,29 +290,6 @@
|
||||
* `FormUtil::toArrayKey()` and `FormUtil::toArrayKeys()` have been removed.
|
||||
They were merged into ChoiceList and have no public equivalent anymore.
|
||||
|
||||
* The options passed to the `getParent()` method of form types no longer
|
||||
contain default options. They only contain the options passed by the user.
|
||||
|
||||
You should check if options exist before attempting to read their value.
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
public function getParent(array $options)
|
||||
{
|
||||
return 'single_text' === $options['widget'] ? 'text' : 'choice';
|
||||
}
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```
|
||||
public function getParent(array $options)
|
||||
{
|
||||
return isset($options['widget']) && 'single_text' === $options['widget'] ? 'text' : 'choice';
|
||||
}
|
||||
```
|
||||
|
||||
* The `add()`, `remove()`, `setParent()`, `bind()` and `setData()` methods in
|
||||
the Form class now throw an exception if the form is already bound.
|
||||
|
||||
@ -611,13 +588,50 @@
|
||||
The second argument `$value` contains the current default value and
|
||||
does not have to be specified if not needed.
|
||||
|
||||
* A third argument $options was added to the methods `buildView()` and
|
||||
`buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`.
|
||||
You should adapt your implementing classes.
|
||||
* No options are passed to `getParent()` of `FormTypeInterface` anymore. If
|
||||
you previously dynamically inherited from FormType or FieldType, you can now
|
||||
dynamically set the "single_control" option instead.
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
public function getParent(array $options)
|
||||
{
|
||||
return $options['expanded'] ? 'form' : 'field';
|
||||
}
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```
|
||||
public function setDefaultOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$singleControl = function (Options $options) {
|
||||
return !$options['expanded'];
|
||||
};
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'single_control' => $singleControl,
|
||||
));
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return 'form';
|
||||
}
|
||||
```
|
||||
|
||||
* A third argument $options was added to the methods `buildView()` and
|
||||
`buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`.
|
||||
Furthermore, `buildViewBottomUp()` was renamed to `finishView()`. At last,
|
||||
all methods in these types now receive instances of `FormBuilderInterface`
|
||||
and `FormViewInterface` where they received instances of `FormBuilder` and
|
||||
`FormView` before. You need to adapt your implementing classes.
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildView(FormView $view, FormInterface $form)
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form)
|
||||
```
|
||||
@ -625,8 +639,9 @@
|
||||
After:
|
||||
|
||||
```
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
public function buildViewBottomUp(FormViewInterface $view, FormInterface $form, array $options)
|
||||
```
|
||||
|
||||
### Validator
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Bridge\Doctrine\Form\Type;
|
||||
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
|
||||
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\EventListener\MergeDoctrineCollectionListener;
|
||||
@ -34,7 +34,7 @@ abstract class DoctrineType extends AbstractType
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
if ($options['multiple']) {
|
||||
$builder
|
||||
@ -94,7 +94,7 @@ abstract class DoctrineType extends AbstractType
|
||||
*/
|
||||
abstract public function getLoader(ObjectManager $manager, $queryBuilder, $class);
|
||||
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'choice';
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace Symfony\Bridge\Propel1\Form\Type;
|
||||
use Symfony\Bridge\Propel1\Form\ChoiceList\ModelChoiceList;
|
||||
use Symfony\Bridge\Propel1\Form\DataTransformer\CollectionToArrayTransformer;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -25,7 +25,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class ModelType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
if ($options['multiple']) {
|
||||
$builder->prependClientTransformer(new CollectionToArrayTransformer());
|
||||
@ -58,7 +58,7 @@ class ModelType extends AbstractType
|
||||
));
|
||||
}
|
||||
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'choice';
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\Event\FilterDataEvent;
|
||||
@ -29,7 +29,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class UserLoginFormType extends AbstractType
|
||||
{
|
||||
private $reqeust;
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @param Request $request A request instance
|
||||
@ -42,7 +42,7 @@ class UserLoginFormType extends AbstractType
|
||||
/**
|
||||
* @see Symfony\Component\Form\AbstractType::buildForm()
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('username', 'text')
|
||||
|
@ -28,21 +28,21 @@ abstract class AbstractType implements FormTypeInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ abstract class AbstractType implements FormTypeInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'form';
|
||||
}
|
||||
|
@ -21,21 +21,21 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,6 @@ CHANGELOG
|
||||
* forms now don't create an empty object anymore if they are completely
|
||||
empty and not required. The empty value for such forms is null.
|
||||
* added constant Guess::VERY_HIGH_CONFIDENCE
|
||||
* [BC BREAK] FormType::getParent() does not see default options anymore
|
||||
* [BC BREAK] The methods `add`, `remove`, `setParent`, `bind` and `setData`
|
||||
in class Form now throw an exception if the form is already bound
|
||||
* fields of constrained classes without a NotBlank or NotNull constraint are
|
||||
@ -95,8 +94,15 @@ CHANGELOG
|
||||
* deprecated the methods `getDefaultOptions` and `getAllowedOptionValues`
|
||||
in FormTypeInterface and FormTypeExtensionInterface
|
||||
* options passed during construction can now be accessed from FormConfigInterface
|
||||
* added FormBuilderInterface, FormViewInterface and FormConfigEditorInterface
|
||||
* [BC BREAK] the methods in FormTypeInterface and FormTypeExtensionInterface now
|
||||
receive FormBuilderInterface and FormViewInterface instead of FormBuilder and
|
||||
FormView
|
||||
* [BC BREAK] the method `buildViewBottomUp` was renamed to `finishView` in
|
||||
FormTypeInterface and FormTypeExtensionInterface
|
||||
* [BC BREAK] the options array is now passed as last argument of the
|
||||
methods
|
||||
* `buildView`
|
||||
* `buildViewBottomUp`
|
||||
* `finishView`
|
||||
in FormTypeInterface and FormTypeExtensionInterface
|
||||
* [BC BREAK] no options are passed to `getParent` of FormTypeInterface anymore
|
||||
|
@ -29,7 +29,7 @@ class BirthdayType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
@ -12,10 +12,10 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class CheckboxType extends AbstractType
|
||||
@ -23,7 +23,7 @@ class CheckboxType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->appendClientTransformer(new BooleanToStringTransformer($options['value']))
|
||||
@ -33,7 +33,7 @@ class CheckboxType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view
|
||||
->set('value', $options['value'])
|
||||
@ -60,7 +60,7 @@ class CheckboxType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -12,9 +12,9 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\Form\Exception\FormException;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
|
||||
@ -34,7 +34,7 @@ class ChoiceType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
if (!$options['choice_list'] && !is_array($options['choices']) && !$options['choices'] instanceof \Traversable) {
|
||||
throw new FormException('Either the option "choices" or "choice_list" must be set.');
|
||||
@ -73,7 +73,7 @@ class ChoiceType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view
|
||||
->set('multiple', $options['multiple'])
|
||||
@ -95,7 +95,7 @@ class ChoiceType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
if ($options['expanded']) {
|
||||
// Radio buttons should have the same name as the parent
|
||||
@ -178,7 +178,7 @@ class ChoiceType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
@ -194,11 +194,11 @@ class ChoiceType extends AbstractType
|
||||
/**
|
||||
* Adds the sub fields for an expanded choice field.
|
||||
*
|
||||
* @param FormBuilder $builder The form builder.
|
||||
* @param array $choiceViews The choice view objects.
|
||||
* @param array $options The build options.
|
||||
* @param FormBuilderInterface $builder The form builder.
|
||||
* @param array $choiceViews The choice view objects.
|
||||
* @param array $options The build options.
|
||||
*/
|
||||
private function addSubForms(FormBuilder $builder, array $choiceViews, array $options)
|
||||
private function addSubForms(FormBuilderInterface $builder, array $choiceViews, array $options)
|
||||
{
|
||||
foreach ($choiceViews as $i => $choiceView) {
|
||||
if (is_array($choiceView)) {
|
||||
|
@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@ -23,7 +23,7 @@ class CollectionType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
if ($options['allow_add'] && $options['prototype']) {
|
||||
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
|
||||
@ -46,7 +46,7 @@ class CollectionType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view
|
||||
->set('allow_add', $options['allow_add'])
|
||||
@ -61,7 +61,7 @@ class CollectionType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
if ($form->getConfig()->hasAttribute('prototype') && $view->get('prototype')->get('multipart')) {
|
||||
$view->set('multipart', true);
|
||||
|
@ -30,7 +30,7 @@ class CountryType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'choice';
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\Form\ReversedTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
|
||||
@ -29,7 +29,7 @@ class DateTimeType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$parts = array('year', 'month', 'day', 'hour', 'minute');
|
||||
$timeParts = array('hour', 'minute');
|
||||
@ -116,7 +116,7 @@ class DateTimeType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->set('widget', $options['widget']);
|
||||
|
||||
@ -197,7 +197,7 @@ class DateTimeType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Exception\CreationException;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
|
||||
@ -31,7 +31,7 @@ class DateType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$format = $options['format'];
|
||||
$pattern = null;
|
||||
@ -136,7 +136,7 @@ class DateType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->set('widget', $options['widget']);
|
||||
|
||||
@ -209,7 +209,7 @@ class DateType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class EmailType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class FileType extends AbstractType
|
||||
@ -21,7 +21,7 @@ class FileType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view
|
||||
->set('type', 'file')
|
||||
@ -32,7 +32,7 @@ class FileType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view
|
||||
->set('multipart', true)
|
||||
@ -52,7 +52,7 @@ class FileType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -14,9 +14,10 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Util\PropertyPath;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
|
||||
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
@ -29,7 +30,7 @@ class FormType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->setRequired($options['required'])
|
||||
@ -53,7 +54,7 @@ class FormType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$name = $form->getName();
|
||||
$readOnly = $options['read_only'];
|
||||
@ -115,7 +116,7 @@ class FormType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$multipart = false;
|
||||
|
||||
@ -216,7 +217,7 @@ class FormType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class HiddenType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -21,7 +21,7 @@ class IntegerType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->appendClientTransformer(
|
||||
new IntegerToLocalizedStringTransformer(
|
||||
@ -61,7 +61,7 @@ class IntegerType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class LanguageType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'choice';
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class LocaleType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'choice';
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class MoneyType extends AbstractType
|
||||
@ -25,7 +25,7 @@ class MoneyType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->appendClientTransformer(new MoneyToLocalizedStringTransformer(
|
||||
@ -40,7 +40,7 @@ class MoneyType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->set('money_pattern', self::getPattern($options['currency']));
|
||||
}
|
||||
@ -62,7 +62,7 @@ class MoneyType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -21,7 +21,7 @@ class NumberType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->appendClientTransformer(new NumberToLocalizedStringTransformer(
|
||||
$options['precision'],
|
||||
@ -59,7 +59,7 @@ class NumberType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class PasswordType extends AbstractType
|
||||
@ -22,7 +22,7 @@ class PasswordType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
if ($options['always_empty'] || !$form->isBound()) {
|
||||
$view->set('value', '');
|
||||
@ -42,7 +42,7 @@ class PasswordType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -21,7 +21,7 @@ class PercentType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->appendClientTransformer(new PercentToLocalizedStringTransformer($options['precision'], $options['type']));
|
||||
}
|
||||
@ -48,7 +48,7 @@ class PercentType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class RadioType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'checkbox';
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@ -22,7 +22,7 @@ class RepeatedType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
// Overwrite required option for child fields
|
||||
$options['first_options']['required'] = $options['required'];
|
||||
|
@ -18,7 +18,7 @@ class SearchType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToStringTransformer;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -21,7 +21,7 @@ class TextType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->appendClientTransformer(new ValueToStringTransformer())
|
||||
@ -41,7 +41,7 @@ class TextType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
class TextareaType extends AbstractType
|
||||
@ -20,7 +20,7 @@ class TextareaType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->set('pattern', null);
|
||||
}
|
||||
@ -28,7 +28,7 @@ class TextareaType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
@ -13,12 +13,12 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\ReversedTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -27,7 +27,7 @@ class TimeType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$parts = array('hour', 'minute');
|
||||
$format = 'H:i';
|
||||
@ -113,7 +113,7 @@ class TimeType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view
|
||||
->set('widget', $options['widget'])
|
||||
@ -193,7 +193,7 @@ class TimeType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'field';
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class TimezoneType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'choice';
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -21,7 +21,7 @@ class UrlType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->addEventSubscriber(new FixUrlProtocolListener($options['default_protocol']));
|
||||
}
|
||||
@ -39,7 +39,7 @@ class UrlType extends AbstractType
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ namespace Symfony\Component\Form\Extension\Csrf\Type;
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
||||
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -41,7 +41,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
||||
* @param FormBuilder $builder The form builder
|
||||
* @param array $options The options
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
if (!$options['csrf_protection']) {
|
||||
return;
|
||||
@ -59,7 +59,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
||||
* @param FormView $view The form view
|
||||
* @param FormInterface $form The form
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form, array $options)
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
if ($options['csrf_protection'] && !$view->hasParent() && !$options['single_control']) {
|
||||
$factory = $form->getConfig()->getAttribute('csrf_factory');
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace Symfony\Component\Form\Extension\Validator\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper;
|
||||
use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener;
|
||||
use Symfony\Component\Validator\ValidatorInterface;
|
||||
@ -43,7 +43,7 @@ class FormTypeValidatorExtension extends AbstractTypeExtension
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->addEventSubscriber(new ValidationListener($this->validator, $this->violationMapper));
|
||||
}
|
||||
|
@ -957,10 +957,10 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
}
|
||||
|
||||
foreach ($types as $type) {
|
||||
$type->buildViewBottomUp($view, $this, $options);
|
||||
$type->finishView($view, $this, $options);
|
||||
|
||||
foreach ($type->getExtensions() as $typeExtension) {
|
||||
$typeExtension->buildViewBottomUp($view, $this, $options);
|
||||
$typeExtension->finishView($view, $this, $options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class FormBuilder extends FormConfig
|
||||
class FormBuilder extends FormConfig implements FormBuilderInterface
|
||||
{
|
||||
/**
|
||||
* The form factory.
|
||||
@ -69,9 +69,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the associated form factory.
|
||||
*
|
||||
* @return FormFactoryInterface The factory
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormFactory()
|
||||
{
|
||||
@ -79,17 +77,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new field to this group. A field must have a unique name within
|
||||
* the group. Otherwise the existing field is overwritten.
|
||||
*
|
||||
* If you add a nested group, this group should also be represented in the
|
||||
* object hierarchy.
|
||||
*
|
||||
* @param string|FormBuilder $child
|
||||
* @param string|FormTypeInterface $type
|
||||
* @param array $options
|
||||
*
|
||||
* @return FormBuilder The builder object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($child, $type = null, array $options = array())
|
||||
{
|
||||
@ -124,13 +112,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form builder.
|
||||
*
|
||||
* @param string $name The name of the form or the name of the property
|
||||
* @param string|FormTypeInterface $type The type of the form or null if name is a property
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return FormBuilder The created builder.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create($name, $type = null, array $options = array())
|
||||
{
|
||||
@ -146,13 +128,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a child by name.
|
||||
*
|
||||
* @param string $name The name of the child
|
||||
*
|
||||
* @return FormBuilder The builder for the child
|
||||
*
|
||||
* @throws FormException if the given child does not exist
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
@ -168,11 +144,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the field with the given name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return FormBuilder The builder object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
@ -189,11 +161,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a field with the given name exists.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Boolean
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
@ -209,9 +177,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the children.
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
@ -221,9 +187,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the form.
|
||||
*
|
||||
* @return Form The form
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
@ -244,9 +208,7 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent builder.
|
||||
*
|
||||
* @return FormBuilder The parent builder
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
@ -254,13 +216,9 @@ class FormBuilder extends FormConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent builder.
|
||||
*
|
||||
* @param FormBuilder $parent The parent builder
|
||||
*
|
||||
* @return FormBuilder The builder object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setParent(FormBuilder $parent = null)
|
||||
public function setParent(FormBuilderInterface $parent = null)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
|
||||
|
109
src/Symfony/Component/Form/FormBuilderInterface.php
Normal file
109
src/Symfony/Component/Form/FormBuilderInterface.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface FormBuilderInterface extends FormConfigEditorInterface
|
||||
{
|
||||
/**
|
||||
* Adds a new field to this group. A field must have a unique name within
|
||||
* the group. Otherwise the existing field is overwritten.
|
||||
*
|
||||
* If you add a nested group, this group should also be represented in the
|
||||
* object hierarchy.
|
||||
*
|
||||
* @param string|FormBuilderInterface $child
|
||||
* @param string|FormTypeInterface $type
|
||||
* @param array $options
|
||||
*
|
||||
* @return FormBuilderInterface The builder object.
|
||||
*/
|
||||
function add($child, $type = null, array $options = array());
|
||||
|
||||
/**
|
||||
* Creates a form builder.
|
||||
*
|
||||
* @param string $name The name of the form or the name of the property
|
||||
* @param string|FormTypeInterface $type The type of the form or null if name is a property
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return FormBuilderInterface The created builder.
|
||||
*/
|
||||
function create($name, $type = null, array $options = array());
|
||||
|
||||
/**
|
||||
* Returns a child by name.
|
||||
*
|
||||
* @param string $name The name of the child
|
||||
*
|
||||
* @return FormBuilderInterface The builder for the child
|
||||
*
|
||||
* @throws Exception\FormException if the given child does not exist
|
||||
*/
|
||||
function get($name);
|
||||
/**
|
||||
* Removes the field with the given name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return FormBuilderInterface The builder object.
|
||||
*/
|
||||
function remove($name);
|
||||
|
||||
/**
|
||||
* Returns whether a field with the given name exists.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
function has($name);
|
||||
|
||||
/**
|
||||
* Returns the children.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function all();
|
||||
|
||||
/**
|
||||
* Returns the associated form factory.
|
||||
*
|
||||
* @return FormFactoryInterface The factory
|
||||
*/
|
||||
function getFormFactory();
|
||||
|
||||
/**
|
||||
* Creates the form.
|
||||
*
|
||||
* @return Form The form
|
||||
*/
|
||||
function getForm();
|
||||
|
||||
/**
|
||||
* Returns the parent builder.
|
||||
*
|
||||
* @return FormBuilderInterface The parent builder
|
||||
*/
|
||||
function getParent();
|
||||
|
||||
/**
|
||||
* Sets the parent builder.
|
||||
*
|
||||
* @param FormBuilderInterface $parent The parent builder
|
||||
*
|
||||
* @return FormBuilderInterface The builder object.
|
||||
*/
|
||||
function setParent(FormBuilderInterface $parent = null);
|
||||
}
|
@ -21,7 +21,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class FormConfig implements FormConfigInterface
|
||||
class FormConfig implements FormConfigEditorInterface
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
@ -146,15 +146,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an event listener to an event on this form.
|
||||
*
|
||||
* @param string $eventName The name of the event to listen to.
|
||||
* @param callable $listener The listener to execute.
|
||||
* @param integer $priority The priority of the listener. Listeners
|
||||
* with a higher priority are called before
|
||||
* listeners with a lower priority.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addEventListener($eventName, $listener, $priority = 0)
|
||||
{
|
||||
@ -164,11 +156,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an event subscriber for events on this form.
|
||||
*
|
||||
* @param EventSubscriberInterface $subscriber The subscriber to attach.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addEventSubscriber(EventSubscriberInterface $subscriber)
|
||||
{
|
||||
@ -178,13 +166,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a validator to the form.
|
||||
*
|
||||
* @param FormValidatorInterface $validator The validator.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addValidator(FormValidatorInterface $validator)
|
||||
{
|
||||
@ -194,11 +176,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a transformer to the client transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $clientTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function appendClientTransformer(DataTransformerInterface $clientTransformer)
|
||||
{
|
||||
@ -208,11 +186,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends a transformer to the client transformer chain.
|
||||
*
|
||||
* @param DataTransformerInterface $clientTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prependClientTransformer(DataTransformerInterface $clientTransformer)
|
||||
{
|
||||
@ -222,9 +196,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the client transformers.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resetClientTransformers()
|
||||
{
|
||||
@ -234,11 +206,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a transformer to the normalization transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $normTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function appendNormTransformer(DataTransformerInterface $normTransformer)
|
||||
{
|
||||
@ -248,11 +216,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends a transformer to the normalization transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $normTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prependNormTransformer(DataTransformerInterface $normTransformer)
|
||||
{
|
||||
@ -262,9 +226,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the normalization transformers.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resetNormTransformers()
|
||||
{
|
||||
@ -346,9 +308,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data mapper of the form.
|
||||
*
|
||||
* @return DataMapperInterface The data mapper.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDataMapper()
|
||||
{
|
||||
@ -460,12 +420,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for an attribute.
|
||||
*
|
||||
* @param string $name The name of the attribute
|
||||
* @param string $value The value of the attribute
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAttribute($name, $value)
|
||||
{
|
||||
@ -475,11 +430,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes.
|
||||
*
|
||||
* @param array $attributes The attributes.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAttributes(array $attributes)
|
||||
{
|
||||
@ -489,11 +440,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data mapper used by the form.
|
||||
*
|
||||
* @param DataMapperInterface $dataMapper
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDataMapper(DataMapperInterface $dataMapper = null)
|
||||
{
|
||||
@ -503,11 +450,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the form is disabled.
|
||||
*
|
||||
* @param Boolean $disabled Whether the form is disabled
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDisabled($disabled)
|
||||
{
|
||||
@ -517,11 +460,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data used for the client data when no value is bound.
|
||||
*
|
||||
* @param mixed $emptyData The empty data.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setEmptyData($emptyData)
|
||||
{
|
||||
@ -531,11 +470,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether errors bubble up to the parent.
|
||||
*
|
||||
* @param Boolean $errorBubbling
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setErrorBubbling($errorBubbling)
|
||||
{
|
||||
@ -545,11 +480,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this field is required to be filled out when bound.
|
||||
*
|
||||
* @param Boolean $required
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRequired($required)
|
||||
{
|
||||
@ -559,13 +490,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property path that the form should be mapped to.
|
||||
*
|
||||
* @param string|PropertyPath $propertyPath The property path or null if the path
|
||||
* should be set automatically based on
|
||||
* the form's name.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPropertyPath($propertyPath)
|
||||
{
|
||||
@ -579,12 +504,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the form should be mapped to an element of its
|
||||
* parent's data.
|
||||
*
|
||||
* @param Boolean $mapped Whether the form should be mapped.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setMapped($mapped)
|
||||
{
|
||||
@ -594,12 +514,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the form's data should be modified by reference.
|
||||
*
|
||||
* @param Boolean $byReference Whether the data should be
|
||||
modified by reference.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setByReference($byReference)
|
||||
{
|
||||
@ -609,11 +524,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the form should be virtual.
|
||||
*
|
||||
* @param Boolean $virtual Whether the form should be virtual.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setVirtual($virtual)
|
||||
{
|
||||
@ -623,11 +534,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the types.
|
||||
*
|
||||
* @param array $types An array FormTypeInterface
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setTypes(array $types)
|
||||
{
|
||||
@ -637,11 +544,7 @@ class FormConfig implements FormConfigInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial data of the form.
|
||||
*
|
||||
* @param array $data The data of the form in application format.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
|
225
src/Symfony/Component/Form/FormConfigEditorInterface.php
Normal file
225
src/Symfony/Component/Form/FormConfigEditorInterface.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface FormConfigEditorInterface extends FormConfigInterface
|
||||
{
|
||||
/**
|
||||
* Adds an event listener to an event on this form.
|
||||
*
|
||||
* @param string $eventName The name of the event to listen to.
|
||||
* @param callable $listener The listener to execute.
|
||||
* @param integer $priority The priority of the listener. Listeners
|
||||
* with a higher priority are called before
|
||||
* listeners with a lower priority.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function addEventListener($eventName, $listener, $priority = 0);
|
||||
|
||||
/**
|
||||
* Adds an event subscriber for events on this form.
|
||||
*
|
||||
* @param EventSubscriberInterface $subscriber The subscriber to attach.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function addEventSubscriber(EventSubscriberInterface $subscriber);
|
||||
|
||||
/**
|
||||
* Adds a validator to the form.
|
||||
*
|
||||
* @param FormValidatorInterface $validator The validator.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
|
||||
*/
|
||||
function addValidator(FormValidatorInterface $validator);
|
||||
|
||||
/**
|
||||
* Appends a transformer to the client transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $clientTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function appendClientTransformer(DataTransformerInterface $clientTransformer);
|
||||
|
||||
/**
|
||||
* Prepends a transformer to the client transformer chain.
|
||||
*
|
||||
* @param DataTransformerInterface $clientTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function prependClientTransformer(DataTransformerInterface $clientTransformer);
|
||||
|
||||
/**
|
||||
* Clears the client transformers.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function resetClientTransformers();
|
||||
|
||||
/**
|
||||
* Appends a transformer to the normalization transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $normTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function appendNormTransformer(DataTransformerInterface $normTransformer);
|
||||
|
||||
/**
|
||||
* Prepends a transformer to the normalization transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $normTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function prependNormTransformer(DataTransformerInterface $normTransformer);
|
||||
|
||||
/**
|
||||
* Clears the normalization transformers.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function resetNormTransformers();
|
||||
|
||||
/**
|
||||
* Sets the value for an attribute.
|
||||
*
|
||||
* @param string $name The name of the attribute
|
||||
* @param string $value The value of the attribute
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setAttribute($name, $value);
|
||||
|
||||
/**
|
||||
* Sets the attributes.
|
||||
*
|
||||
* @param array $attributes The attributes.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setAttributes(array $attributes);
|
||||
|
||||
/**
|
||||
* Sets the data mapper used by the form.
|
||||
*
|
||||
* @param DataMapperInterface $dataMapper
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setDataMapper(DataMapperInterface $dataMapper = null);
|
||||
|
||||
/**
|
||||
* Set whether the form is disabled.
|
||||
*
|
||||
* @param Boolean $disabled Whether the form is disabled
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setDisabled($disabled);
|
||||
|
||||
/**
|
||||
* Sets the data used for the client data when no value is bound.
|
||||
*
|
||||
* @param mixed $emptyData The empty data.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setEmptyData($emptyData);
|
||||
|
||||
/**
|
||||
* Sets whether errors bubble up to the parent.
|
||||
*
|
||||
* @param Boolean $errorBubbling
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setErrorBubbling($errorBubbling);
|
||||
|
||||
/**
|
||||
* Sets whether this field is required to be filled out when bound.
|
||||
*
|
||||
* @param Boolean $required
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setRequired($required);
|
||||
|
||||
/**
|
||||
* Sets the property path that the form should be mapped to.
|
||||
*
|
||||
* @param string|PropertyPath $propertyPath The property path or null if the path
|
||||
* should be set automatically based on
|
||||
* the form's name.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setPropertyPath($propertyPath);
|
||||
|
||||
/**
|
||||
* Sets whether the form should be mapped to an element of its
|
||||
* parent's data.
|
||||
*
|
||||
* @param Boolean $mapped Whether the form should be mapped.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setMapped($mapped);
|
||||
|
||||
/**
|
||||
* Sets whether the form's data should be modified by reference.
|
||||
*
|
||||
* @param Boolean $byReference Whether the data should be
|
||||
modified by reference.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setByReference($byReference);
|
||||
|
||||
/**
|
||||
* Sets whether the form should be virtual.
|
||||
*
|
||||
* @param Boolean $virtual Whether the form should be virtual.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setVirtual($virtual);
|
||||
|
||||
/**
|
||||
* Set the types.
|
||||
*
|
||||
* @param array $types An array FormTypeInterface
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setTypes(array $types);
|
||||
|
||||
/**
|
||||
* Sets the initial data of the form.
|
||||
*
|
||||
* @param array $data The data of the form in application format.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function setData($data);
|
||||
}
|
@ -21,43 +21,43 @@ interface FormTypeExtensionInterface
|
||||
/**
|
||||
* Builds the form.
|
||||
*
|
||||
* This method gets called after the extended type has built the form to
|
||||
* This method is called after the extended type has built the form to
|
||||
* further modify it.
|
||||
*
|
||||
* @see FormTypeInterface::buildForm()
|
||||
*
|
||||
* @param FormBuilder $builder The form builder
|
||||
* @param array $options The options
|
||||
* @param FormBuilderInterface $builder The form builder
|
||||
* @param array $options The options
|
||||
*/
|
||||
function buildForm(FormBuilder $builder, array $options);
|
||||
function buildForm(FormBuilderInterface $builder, array $options);
|
||||
|
||||
/**
|
||||
* Builds the view.
|
||||
*
|
||||
* This method gets called after the extended type has built the view to
|
||||
* This method is called after the extended type has built the view to
|
||||
* further modify it.
|
||||
*
|
||||
* @see FormTypeInterface::buildView()
|
||||
*
|
||||
* @param FormView $view The view
|
||||
* @param FormInterface $form The form
|
||||
* @param array $options The options
|
||||
* @param FormViewInterface $view The view
|
||||
* @param FormInterface $form The form
|
||||
* @param array $options The options
|
||||
*/
|
||||
function buildView(FormView $view, FormInterface $form, array $options);
|
||||
function buildView(FormViewInterface $view, FormInterface $form, array $options);
|
||||
|
||||
/**
|
||||
* Builds the view.
|
||||
* Finishes the view.
|
||||
*
|
||||
* This method gets called after the extended type has built the view to
|
||||
* This method is called after the extended type has finished the view to
|
||||
* further modify it.
|
||||
*
|
||||
* @see FormTypeInterface::buildViewBottomUp()
|
||||
* @see FormTypeInterface::finishView()
|
||||
*
|
||||
* @param FormView $view The view
|
||||
* @param FormInterface $form The form
|
||||
* @param array $options The options
|
||||
* @param FormViewInterface $view The view
|
||||
* @param FormInterface $form The form
|
||||
* @param array $options The options
|
||||
*/
|
||||
function buildViewBottomUp(FormView $view, FormInterface $form, array $options);
|
||||
function finishView(FormViewInterface $view, FormInterface $form, array $options);
|
||||
|
||||
/**
|
||||
* Overrides the default options from the extended type.
|
||||
|
@ -21,49 +21,52 @@ interface FormTypeInterface
|
||||
/**
|
||||
* Builds the form.
|
||||
*
|
||||
* This method gets called for each type in the hierarchy starting form the
|
||||
* top most type.
|
||||
* Type extensions can further modify the form.
|
||||
* This method is called for each type in the hierarchy starting form the
|
||||
* top most type. Type extensions can further modify the form.
|
||||
*
|
||||
* @see FormTypeExtensionInterface::buildForm()
|
||||
*
|
||||
* @param FormBuilder $builder The form builder
|
||||
* @param array $options The options
|
||||
* @param FormBuilderInterface $builder The form builder
|
||||
* @param array $options The options
|
||||
*/
|
||||
function buildForm(FormBuilder $builder, array $options);
|
||||
function buildForm(FormBuilderInterface $builder, array $options);
|
||||
|
||||
/**
|
||||
* Builds the form view.
|
||||
*
|
||||
* This method gets called for each type in the hierarchy starting form the
|
||||
* top most type.
|
||||
* Type extensions can further modify the view.
|
||||
* This method is called for each type in the hierarchy starting form the
|
||||
* top most type. Type extensions can further modify the view.
|
||||
*
|
||||
* A view of a form is built before the views of the child forms are built.
|
||||
* This means that you cannot access child views in this method. If you need
|
||||
* to do so, move your logic to {@link finishView()} instead.
|
||||
*
|
||||
* @see FormTypeExtensionInterface::buildView()
|
||||
*
|
||||
* @param FormView $view The view
|
||||
* @param FormInterface $form The form
|
||||
* @param array $options The options
|
||||
* @param FormViewInterface $view The view
|
||||
* @param FormInterface $form The form
|
||||
* @param array $options The options
|
||||
*/
|
||||
function buildView(FormView $view, FormInterface $form, array $options);
|
||||
function buildView(FormViewInterface $view, FormInterface $form, array $options);
|
||||
|
||||
/**
|
||||
* Builds the form view.
|
||||
* Finishes the form view.
|
||||
*
|
||||
* This method gets called for each type in the hierarchy starting form the
|
||||
* top most type.
|
||||
* Type extensions can further modify the view.
|
||||
* top most type. Type extensions can further modify the view.
|
||||
*
|
||||
* Children views have been built when this method gets called so you get
|
||||
* a chance to modify them.
|
||||
* When this method is called, views of the form's children have already
|
||||
* been built and finished and can be accessed. You should only implement
|
||||
* such logic in this method that actually accesses child views. For everything
|
||||
* else you are recommended to implement {@link buildView()} instead.
|
||||
*
|
||||
* @see FormTypeExtensionInterface::buildViewBottomUp()
|
||||
* @see FormTypeExtensionInterface::finishView()
|
||||
*
|
||||
* @param FormView $view The view
|
||||
* @param FormInterface $form The form
|
||||
* @param array $options The options
|
||||
* @param FormViewInterface $view The view
|
||||
* @param FormInterface $form The form
|
||||
* @param array $options The options
|
||||
*/
|
||||
function buildViewBottomUp(FormView $view, FormInterface $form, array $options);
|
||||
function finishView(FormViewInterface $view, FormInterface $form, array $options);
|
||||
|
||||
/**
|
||||
* Returns a builder for the current type.
|
||||
@ -75,7 +78,7 @@ interface FormTypeInterface
|
||||
* @param FormFactoryInterface $factory The form factory
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return FormBuilder|null A form builder or null when the type does not have a builder
|
||||
* @return FormBuilderInterface|null A form builder or null when the type does not have a builder
|
||||
*/
|
||||
function createBuilder($name, FormFactoryInterface $factory, array $options);
|
||||
|
||||
@ -89,11 +92,9 @@ interface FormTypeInterface
|
||||
/**
|
||||
* Returns the name of the parent type.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return string|null The name of the parent type if any otherwise null
|
||||
* @return string|null The name of the parent type if any, null otherwise.
|
||||
*/
|
||||
function getParent(array $options);
|
||||
function getParent();
|
||||
|
||||
/**
|
||||
* Returns the name of this type.
|
||||
|
@ -11,14 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use ArrayAccess;
|
||||
use IteratorAggregate;
|
||||
use Countable;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
class FormView implements \IteratorAggregate, FormViewInterface
|
||||
{
|
||||
private $name;
|
||||
|
||||
@ -47,16 +43,16 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return FormView The current view
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
@ -66,9 +62,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return Boolean
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
@ -76,10 +70,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $default
|
||||
*
|
||||
* @return mixed
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
@ -91,7 +82,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
@ -124,9 +115,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the attached form is rendered.
|
||||
*
|
||||
* @return Boolean Whether the form is rendered
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isRendered()
|
||||
{
|
||||
@ -150,9 +139,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the attached form as rendered
|
||||
*
|
||||
* @return FormView The current view
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRendered()
|
||||
{
|
||||
@ -162,13 +149,9 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent view.
|
||||
*
|
||||
* @param FormView $parent The parent view
|
||||
*
|
||||
* @return FormView The current view
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setParent(FormView $parent = null)
|
||||
public function setParent(FormViewInterface $parent = null)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
|
||||
@ -176,9 +159,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent view.
|
||||
*
|
||||
* @return FormView The parent view
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
@ -186,9 +167,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this view has a parent.
|
||||
*
|
||||
* @return Boolean Whether this view has a parent
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasParent()
|
||||
{
|
||||
@ -196,13 +175,9 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a child view.
|
||||
*
|
||||
* @param FormView $child The child view to add.
|
||||
*
|
||||
* @return FormView The current view
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addChild(FormView $child)
|
||||
public function addChild(FormViewInterface $child)
|
||||
{
|
||||
$this->children[$child->getName()] = $child;
|
||||
|
||||
@ -210,11 +185,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a child view.
|
||||
*
|
||||
* @param string $name The name of the removed child view.
|
||||
*
|
||||
* @return FormView The current view
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeChild($name)
|
||||
{
|
||||
@ -224,9 +195,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the children.
|
||||
*
|
||||
* @return array The children as instances of FormView
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
@ -234,11 +203,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a given child.
|
||||
*
|
||||
* @param string $name The name of the child
|
||||
*
|
||||
* @return FormView The child view
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChild($name)
|
||||
{
|
||||
@ -246,9 +211,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this view has children.
|
||||
*
|
||||
* @return Boolean Whether this view has children
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasChildren()
|
||||
{
|
||||
@ -256,11 +219,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this view has a given child.
|
||||
*
|
||||
* @param string $name The name of the child
|
||||
*
|
||||
* @return Boolean Whether the child with the given name exists
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasChild($name)
|
||||
{
|
||||
|
148
src/Symfony/Component/Form/FormViewInterface.php
Normal file
148
src/Symfony/Component/Form/FormViewInterface.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable
|
||||
{
|
||||
/**
|
||||
* Returns the name of the form.
|
||||
*
|
||||
* @return string The form name.
|
||||
*/
|
||||
function getName();
|
||||
|
||||
/**
|
||||
* Sets a view variable.
|
||||
*
|
||||
* @param string $name The variable name.
|
||||
* @param string $value The variable value.
|
||||
*
|
||||
* @return FormViewInterface The view object.
|
||||
*/
|
||||
function set($name, $value);
|
||||
|
||||
/**
|
||||
* Returns whether a view variable exists.
|
||||
*
|
||||
* @param string $name The variable name.
|
||||
*
|
||||
* @return Boolean Whether the variable exists.
|
||||
*/
|
||||
function has($name);
|
||||
|
||||
/**
|
||||
* Returns the value of a view variable.
|
||||
*
|
||||
* @param string $name The variable name.
|
||||
* @param mixed $default The value to return if the variable is not set.
|
||||
*
|
||||
* @return mixed The variable value.
|
||||
*/
|
||||
function get($name, $default = null);
|
||||
|
||||
/**
|
||||
* Returns the values of all view variables.
|
||||
*
|
||||
* @return array The values of all variables.
|
||||
*/
|
||||
function all();
|
||||
|
||||
/**
|
||||
* Returns whether the view was already rendered.
|
||||
*
|
||||
* @return Boolean Whether this view's widget is rendered.
|
||||
*/
|
||||
function isRendered();
|
||||
|
||||
/**
|
||||
* Marks the view as rendered.
|
||||
*
|
||||
* @return FormViewInterface The view object.
|
||||
*/
|
||||
function setRendered();
|
||||
|
||||
/**
|
||||
* Sets the parent view.
|
||||
*
|
||||
* @param FormViewInterface $parent The parent view.
|
||||
*
|
||||
* @return FormViewInterface The view object.
|
||||
*/
|
||||
function setParent(FormViewInterface $parent = null);
|
||||
|
||||
/**
|
||||
* Returns the parent view.
|
||||
*
|
||||
* @return FormViewInterface The parent view.
|
||||
*/
|
||||
function getParent();
|
||||
|
||||
/**
|
||||
* Returns whether this view has a parent.
|
||||
*
|
||||
* @return Boolean Whether this view has a parent
|
||||
*/
|
||||
function hasParent();
|
||||
|
||||
/**
|
||||
* Adds a child view.
|
||||
*
|
||||
* @param FormViewInterface $child The child view to add.
|
||||
*
|
||||
* @return FormViewInterface The view object.
|
||||
*/
|
||||
function addChild(FormViewInterface $child);
|
||||
|
||||
/**
|
||||
* Removes a child view.
|
||||
*
|
||||
* @param string $name The name of the removed child view.
|
||||
*
|
||||
* @return FormViewInterface The view object.
|
||||
*/
|
||||
function removeChild($name);
|
||||
|
||||
/**
|
||||
* Returns the children.
|
||||
*
|
||||
* @return array The children as instances of FormView
|
||||
*/
|
||||
function getChildren();
|
||||
|
||||
/**
|
||||
* Returns a given child.
|
||||
*
|
||||
* @param string $name The name of the child
|
||||
*
|
||||
* @return FormViewInterface The child view
|
||||
*/
|
||||
function getChild($name);
|
||||
|
||||
/**
|
||||
* Returns whether this view has children.
|
||||
*
|
||||
* @return Boolean Whether this view has children
|
||||
*/
|
||||
function hasChildren();
|
||||
|
||||
/**
|
||||
* Returns whether this view has a given child.
|
||||
*
|
||||
* @param string $name The name of the child
|
||||
*
|
||||
* @return Boolean Whether the child with the given name exists
|
||||
*/
|
||||
function hasChild($name);
|
||||
}
|
@ -12,13 +12,13 @@
|
||||
namespace Symfony\Component\Form\Tests\Extension\Csrf\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
|
||||
use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase;
|
||||
|
||||
class FormTypeCsrfExtensionTest_ChildType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
// The form needs a child in order to trigger CSRF protection by
|
||||
// default
|
||||
|
@ -3,12 +3,12 @@
|
||||
namespace Symfony\Component\Form\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AuthorType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('firstName')
|
||||
|
@ -13,12 +13,13 @@ namespace Symfony\Component\Form\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
|
||||
class FooType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->setAttribute('foo', 'x');
|
||||
$builder->setAttribute('data_option', $options['data']);
|
||||
@ -51,7 +52,7 @@ class FooType extends AbstractType
|
||||
);
|
||||
}
|
||||
|
||||
public function getParent(array $options)
|
||||
public function getParent()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -12,11 +12,11 @@
|
||||
namespace Symfony\Component\Form\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class FooTypeBarExtension extends AbstractTypeExtension
|
||||
{
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->setAttribute('bar', 'x');
|
||||
}
|
||||
|
@ -12,11 +12,11 @@
|
||||
namespace Symfony\Component\Form\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class FooTypeBazExtension extends AbstractTypeExtension
|
||||
{
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->setAttribute('baz', 'x');
|
||||
}
|
||||
|
@ -1132,30 +1132,30 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
}));
|
||||
|
||||
$type1->expects($this->once())
|
||||
->method('buildViewBottomUp')
|
||||
->method('finishView')
|
||||
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
|
||||
$calls[] = 'type1::buildViewBottomUp';
|
||||
$calls[] = 'type1::finishView';
|
||||
$test->assertTrue($view->hasChildren());
|
||||
}));
|
||||
|
||||
$type1Extension->expects($this->once())
|
||||
->method('buildViewBottomUp')
|
||||
->method('finishView')
|
||||
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
|
||||
$calls[] = 'type1ext::buildViewBottomUp';
|
||||
$calls[] = 'type1ext::finishView';
|
||||
$test->assertTrue($view->hasChildren());
|
||||
}));
|
||||
|
||||
$type2->expects($this->once())
|
||||
->method('buildViewBottomUp')
|
||||
->method('finishView')
|
||||
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
|
||||
$calls[] = 'type2::buildViewBottomUp';
|
||||
$calls[] = 'type2::finishView';
|
||||
$test->assertTrue($view->hasChildren());
|
||||
}));
|
||||
|
||||
$type2Extension->expects($this->once())
|
||||
->method('buildViewBottomUp')
|
||||
->method('finishView')
|
||||
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
|
||||
$calls[] = 'type2ext::buildViewBottomUp';
|
||||
$calls[] = 'type2ext::finishView';
|
||||
$test->assertTrue($view->hasChildren());
|
||||
}));
|
||||
|
||||
@ -1170,10 +1170,10 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
1 => 'type1ext::buildView',
|
||||
2 => 'type2::buildView',
|
||||
3 => 'type2ext::buildView',
|
||||
4 => 'type1::buildViewBottomUp',
|
||||
5 => 'type1ext::buildViewBottomUp',
|
||||
6 => 'type2::buildViewBottomUp',
|
||||
7 => 'type2ext::buildViewBottomUp',
|
||||
4 => 'type1::finishView',
|
||||
5 => 'type1ext::finishView',
|
||||
6 => 'type2::finishView',
|
||||
7 => 'type2ext::finishView',
|
||||
), $calls);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user