src/JuridicusBundle/Form/Type/HandynummerType.php line 10

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Form\Type;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\Form\Extension\Core\Type\FormType;
  6. use JF\JuridicusBundle\Form\DataTransformer\StringToHandynummerTransformer;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. class HandynummerType extends AbstractType
  9. {
  10. private $vorwahlChoices;
  11. public function __construct(array $vorwahlChoices = [])
  12. {
  13. $this->vorwahlChoices = $vorwahlChoices ?: ['+49', '+41', '+43'];
  14. }
  15. public function buildForm(FormBuilderInterface $builder, array $options)
  16. {
  17. $builder
  18. ->add('vorwahl', ChoiceType::class, array(
  19. 'required' => true,
  20. 'choices' => $this->vorwahlChoices,
  21. 'placeholder' => '----',
  22. 'attr' => array('class' => 'input-small')
  23. ))
  24. ->add('rufnummer', null, array(
  25. 'required' => true
  26. ))
  27. ;
  28. $transformer = new StringToHandynummerTransformer();
  29. $builder->addModelTransformer($transformer);
  30. }
  31. public function getParent()
  32. {
  33. return FormType::class; //changedFrom 'field'
  34. }
  35. public function getHandynummerType()
  36. {
  37. return 'handynummer';
  38. }
  39. public function getName()
  40. {
  41. return 'handynummer';
  42. }
  43. }