Created
August 24, 2017 14:35
-
-
Save miedzwin/3754d200827bfe3ad4b4a78d8b535e1c 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
{% extends "::base.html.twig"%} | |
{% block body %} | |
<div> | |
{{ form_start(form) }} | |
{{ form_label(form.name) }} | |
{{ form_widget(form.name) }} | |
{% block choice_widget_options %} | |
{% spaceless %} | |
{% for group_label, choice in form.photo %} | |
{% if choice is iterable %} | |
<label for="{{ choice.vars.id }}"><img src="{{ choice.vars.label }}" width="128" height="128"/></label> | |
<input type="radio" id="{{ choice.vars.id }}" name="{{ choice.vars.full_name }}" value="{{ choice.vars.value }}"/> | |
{% else %} | |
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}> | |
<img src="/images/flags/{{ choice.label }}.jpg" /> | |
{{ choice.label|trans }} | |
</option> | |
{% endif %} | |
{% endfor %} | |
{% endspaceless %} | |
{% endblock choice_widget_options %} | |
{#{{ form_label(form.photo) }} | |
{{ form_widget(form.photo) }}#} | |
{{ form_label(form.trainingTypes) }} | |
{{ form_widget(form.trainingTypes) }} | |
{{ form_label(form.equipments) }} | |
{{ form_widget(form.equipments) }} | |
{{ form_label(form.duration) }} | |
{{ form_widget(form.duration) }} | |
{{ form_label(form.availablePlaces) }} | |
{{ form_widget(form.availablePlaces) }} | |
{{ form_label(form.description) }} | |
{{ form_widget(form.description) }} | |
{{ form_label(form.submit) }} | |
{{ form_widget(form.submit) }} | |
{{ form_end(form) }} | |
</div> | |
{% endblock body %} |
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 AppBundle\Form; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
use Symfony\Component\Form\Extension\Core\Type\TextType; | |
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | |
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |
use AppBundle\Entity\TrainingType; | |
use AppBundle\Entity\Equipment; | |
use AppBundle\Entity\Training; | |
use AppBundle\Entity\Photo; | |
class CreateTrainingType extends AbstractType { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function buildForm(FormBuilderInterface $builder, array $options) { | |
$builder->add('name', TextType::class, [ | |
'label' => 'training_create_form.name', | |
]); | |
$builder->add('photo', EntityType::class, [ | |
'class' => Photo::class, | |
'choice_label' => 'url', | |
'label' => 'training_create_form.training_photo', | |
'choice_translation_domain' => true, | |
'required' => false, | |
'expanded' => true, | |
]); | |
$builder->add('trainingTypes', EntityType::class, [ | |
'class' => TrainingType::class, | |
'choice_label' => 'name', | |
'label' => 'training_create_form.training_types', | |
'choice_translation_domain' => true, | |
'multiple' => true, | |
'expanded' => true, | |
'required' => false, | |
]); | |
$builder->add('equipments', EntityType::class, [ | |
'class' => Equipment::class, | |
'choice_label' => 'name', | |
'label' => 'training_create_form.equipments', | |
'choice_translation_domain' => true, | |
'required' => false, | |
'multiple' => true, | |
'expanded' => true, | |
]); | |
$builder->add('duration', ChoiceType::class, [ | |
'label' => 'training_create_form.training_duration', | |
'placeholder' => 'training_create_form.training_duration', | |
'required' => false, | |
'choice_translation_domain' => true, | |
'choices' => $options['duration_minutes'], | |
'choice_translation_domain' => false, | |
]); | |
$builder->add('availablePlaces', ChoiceType::class, [ | |
'label' => 'training_create_form.available_places', | |
'placeholder' => 'training_create_form.available_places', | |
'required' => false, | |
'choice_translation_domain' => true, | |
'choices' => $options['available_places'], | |
]); | |
$builder->add('description', TextareaType::class, [ | |
'label' => 'training_create_form.description', | |
'required' => false, | |
]); | |
$builder->add('submit', SubmitType::class, [ | |
'label' => 'common.save', | |
]); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function configureOptions(OptionsResolver $resolver) { | |
$resolver->setDefaults(array( | |
'data_class' => Training::class, | |
'duration_minutes' => [ | |
'0' => 0, | |
'15' => 15, | |
'30' => 30, | |
'45' => 45, | |
'60' => 60, | |
'75' => 75, | |
'90' => 90, | |
'105' => 105, | |
'120' => 120, | |
], | |
'price' => $this->generateValuesArray(20), | |
'available_places' => [ | |
'training_create_form.personal' => 1, | |
'training_create_form.small' => 5, | |
'training_create_form.large' => 10, | |
], | |
)); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getBlockPrefix() { | |
return 'appbundle_training'; | |
} | |
/** | |
* | |
* @param int $range | |
* @return array | |
*/ | |
private function generateValuesArray(int $range): array { | |
$arr = []; | |
for ($i = 0; $i < $range; $i++) { | |
$arr[$i] = $i; | |
} | |
return $arr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment