CheckboxFieldConfig.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\BooleanToStringTransformer;
  13. use Symfony\Component\Form\Renderer\Plugin\CheckedPlugin;
  14. class CheckboxFieldConfig extends AbstractFieldConfig
  15. {
  16. public function configure(FieldInterface $field, array $options)
  17. {
  18. $field->setValueTransformer(new BooleanToStringTransformer())
  19. ->addRendererPlugin(new CheckedPlugin())
  20. ->setRendererVar('value', $options['value']);
  21. }
  22. public function getDefaultOptions(array $options)
  23. {
  24. return array(
  25. 'template' => 'checkbox',
  26. 'value' => '1',
  27. );
  28. }
  29. public function getParent(array $options)
  30. {
  31. return 'field';
  32. }
  33. public function getIdentifier()
  34. {
  35. return 'checkbox';
  36. }
  37. }