RepeatedFieldConfig.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form\Config;
  11. use Symfony\Component\Form\FieldInterface;
  12. use Symfony\Component\Form\ValueTransformer\ValueToDuplicatesTransformer;
  13. class RepeatedFieldConfig extends AbstractFieldConfig
  14. {
  15. public function configure(FieldInterface $field, array $options)
  16. {
  17. $field->setValueTransformer(new ValueToDuplicatesTransformer(array(
  18. $options['first_key'],
  19. $options['second_key'],
  20. )))
  21. ->add($this->getInstance($options['identifier'], $options['first_key'], $options['options']))
  22. ->add($this->getInstance($options['identifier'], $options['second_key'], $options['options']));
  23. }
  24. public function getDefaultOptions(array $options)
  25. {
  26. return array(
  27. 'template' => 'repeated',
  28. 'identifier' => 'text',
  29. 'options' => array(),
  30. 'first_key' => 'first',
  31. 'second_key' => 'second',
  32. 'csrf_protection' => false,
  33. );
  34. }
  35. public function getParent(array $options)
  36. {
  37. return 'form';
  38. }
  39. public function getIdentifier()
  40. {
  41. return 'repeated';
  42. }
  43. }