Last active
December 30, 2015 03:59
-
-
Save zerrvox/7772619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CreateScheduleTemplateType extends AbstractType | |
{ | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults( | |
[ | |
'required' => true, | |
'type' => 'Melin\ModulePlannerBundle\Form\Type\ScheduleTemplate', | |
'csrf_protection' => false, | |
'cascade_validation' => true | |
] | |
); | |
} | |
public function getName() | |
{ | |
return ''; | |
} | |
public function getParent() | |
{ | |
return 'collection'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"weekday": 10, | |
"time": "09:00", | |
"time_slot_length": 180, | |
"time_slot_type_id": "00000000-0000-1200-a001-000000000001" | |
}, | |
{ | |
"weekday": 8, | |
"time": "12:00", | |
"time_slot_length": 60, | |
"time_slot_type_id": "00000000-0000-1200-a002-000000000002" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Melin\ModulePlannerBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilder; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Symfony\Component\Validator\Constraints\Range; | |
use JMS\TranslationBundle\Annotation\Ignore; | |
class CreateScheduleTemplateType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add( | |
'weekday', | |
'integer', | |
[ | |
'required' => true, | |
'constraints' => [ | |
new Assert\Range([ | |
'min' => 1, | |
'max' => 7, | |
'minMessage' => 'Weekday must be a number between 1 (Monday) and 7 (Sunday). {{ value }} was given.', | |
'maxMessage' => 'Weekday must be a number between 1 (Monday) and 7 (Sunday). {{ value }} was given.', | |
]) | |
] | |
] | |
) | |
->add( | |
'time', | |
'text', | |
[ | |
'required' => true, | |
'constraints' => [ | |
new Assert\Regex([ | |
'pattern' => '/^[0-2][0-9]:[0-5][0-9]/', | |
'match' => true, | |
'message' => 'Time is not the right format (HH:mm)', | |
]) | |
] | |
] | |
) | |
->add( | |
'time_slot_length', | |
'integer', | |
[ | |
'required' => true, | |
'constraints' => [new Assert\NotBlank()], | |
'property_path' => 'timeSlotLength' | |
] | |
) | |
->add( | |
'time_slot_type_id', | |
'uuid', | |
[ | |
'required' => true, | |
'constraints' => [new Assert\NotBlank()], | |
'property_path' => 'timeSlotTypeId' | |
] | |
); | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults( | |
array( | |
'data_class' => 'Melin\ModulePlannerBundle\Model\ScheduleTemplate', | |
'csrf_protection' => false | |
) | |
); | |
} | |
public function getName() | |
{ | |
return 'schedule_template'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment