Skip to content

Instantly share code, notes, and snippets.

@zerrvox
Last active December 30, 2015 03:59
Show Gist options
  • Save zerrvox/7772619 to your computer and use it in GitHub Desktop.
Save zerrvox/7772619 to your computer and use it in GitHub Desktop.
<?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';
}
}
[
{
"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"
}
]
<?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