mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge remote-tracking branch 'origin/improve_location' into 106_tasks_to_parcours
This commit is contained in:
85
src/Bundle/ChillMainBundle/Form/LocationFormType.php
Normal file
85
src/Bundle/ChillMainBundle/Form/LocationFormType.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\LocationType as EntityLocationType;
|
||||
use Chill\MainBundle\Form\Type\PickAddressType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
final class LocationFormType extends AbstractType
|
||||
{
|
||||
|
||||
// private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
// /**
|
||||
// * @param TranslatableStringHelper $translatableStringHelper
|
||||
// */
|
||||
// public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
// {
|
||||
// $this->translatableStringHelper = $translatableStringHelper;
|
||||
// }
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
|
||||
$builder
|
||||
->add('locationType', EntityType::class, [
|
||||
'class' => EntityLocationType::class,
|
||||
'choice_attr' => function (EntityLocationType $entity) {
|
||||
return [
|
||||
'data-address' => $entity->getAddressRequired(),
|
||||
'data-contact' => $entity->getContactData(),
|
||||
];
|
||||
},
|
||||
'choice_label' => function (EntityLocationType $entity) {
|
||||
//return $this->translatableStringHelper->localize($entity->getTitle()); //TODO not working. Cannot pass smthg in the constructor
|
||||
return $entity->getTitle()['fr'];
|
||||
},
|
||||
])
|
||||
->add('name', TextType::class)
|
||||
->add('phonenumber1', TextType::class, ['required' => false])
|
||||
->add('phonenumber2', TextType::class, ['required' => false])
|
||||
->add('email', TextType::class, ['required' => false])
|
||||
->add('address', PickAddressType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Address',
|
||||
'use_valid_from' => false,
|
||||
'use_valid_to' => false,
|
||||
'mapped' => false,
|
||||
])
|
||||
->add('active', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false
|
||||
],
|
||||
'expanded' => true
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param OptionsResolverInterface $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\MainBundle\Entity\Location'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'chill_mainbundle_location';
|
||||
}
|
||||
|
||||
}
|
54
src/Bundle/ChillMainBundle/Form/LocationTypeType.php
Normal file
54
src/Bundle/ChillMainBundle/Form/LocationTypeType.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\LocationType;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final class LocationTypeType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('title', TranslatableStringFormType::class,
|
||||
[
|
||||
'label' => 'Name',
|
||||
])
|
||||
->add('availableForUsers', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false
|
||||
],
|
||||
'expanded' => true
|
||||
])
|
||||
->add('addressRequired', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'optional' => LocationType::STATUS_OPTIONAL,
|
||||
'required' => LocationType::STATUS_REQUIRED,
|
||||
'never' => LocationType::STATUS_NEVER,
|
||||
],
|
||||
'expanded' => true
|
||||
])
|
||||
->add('contactData', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'optional' => LocationType::STATUS_OPTIONAL,
|
||||
'required' => LocationType::STATUS_REQUIRED,
|
||||
'never' => LocationType::STATUS_NEVER,
|
||||
],
|
||||
'expanded' => true
|
||||
])
|
||||
->add('active', ChoiceType::class,
|
||||
[
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false
|
||||
],
|
||||
'expanded' => true
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user