From e24fd8aff0016c918769f7f7ee108aa7185260da Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 22 Oct 2021 10:01:24 +0200 Subject: [PATCH] location admin: improve admin crud for location --- .../Controller/LocationController.php | 18 ++++++---- .../ChillMainExtension.php | 2 +- ...{LocationType.php => LocationFormType.php} | 34 +++++++++++++++---- .../Resources/views/Location/index.html.twig | 8 ++--- .../ChillMainBundle/config/services/form.yaml | 8 +++-- .../translations/messages.fr.yml | 3 ++ 6 files changed, 54 insertions(+), 19 deletions(-) rename src/Bundle/ChillMainBundle/Form/{LocationType.php => LocationFormType.php} (66%) diff --git a/src/Bundle/ChillMainBundle/Controller/LocationController.php b/src/Bundle/ChillMainBundle/Controller/LocationController.php index 75bc01262..e6aba8fc3 100644 --- a/src/Bundle/ChillMainBundle/Controller/LocationController.php +++ b/src/Bundle/ChillMainBundle/Controller/LocationController.php @@ -9,11 +9,17 @@ class LocationController extends CRUDController { public function customizeQuery(string $action, Request $request, $query): void { - $query->where('e.availableForUsers', "'TRUE'"); + //$query->where('e.availableforusers', "'TRUE'"); // not working + $query->where('e.availableForUsers = true'); //TODO not working } - // public function createEntity(string $action, Request $request): object - // { - - // } -} + + public function createEntity(string $action, Request $request): object + { + $entity = parent::createEntity($action, $request); + + $entity->setAvailableForUsers(true); + + return $entity; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 5574556f2..972c046d9 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -49,7 +49,7 @@ use Chill\MainBundle\Doctrine\Type\PointType; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\LocationType; use Chill\MainBundle\Form\LocationTypeType; -use Chill\MainBundle\Form\LocationType as LocationFormType; +use Chill\MainBundle\Form\LocationFormType; use Symfony\Component\HttpFoundation\Request; /** diff --git a/src/Bundle/ChillMainBundle/Form/LocationType.php b/src/Bundle/ChillMainBundle/Form/LocationFormType.php similarity index 66% rename from src/Bundle/ChillMainBundle/Form/LocationType.php rename to src/Bundle/ChillMainBundle/Form/LocationFormType.php index 5bf71734c..b4811bad1 100644 --- a/src/Bundle/ChillMainBundle/Form/LocationType.php +++ b/src/Bundle/ChillMainBundle/Form/LocationFormType.php @@ -2,7 +2,6 @@ namespace Chill\MainBundle\Form; -use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\LocationType as EntityLocationType; use Chill\MainBundle\Form\Type\PickAddressType; use Chill\MainBundle\Templating\TranslatableStringHelper; @@ -10,15 +9,18 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; -final class LocationType extends AbstractType +final class LocationFormType extends AbstractType { // private TranslatableStringHelper $translatableStringHelper; - // public function __construct( - // TranslatableStringHelper $translatableStringHelper - // ) { + // /** + // * @param TranslatableStringHelper $translatableStringHelper + // */ + // public function __construct(TranslatableStringHelper $translatableStringHelper) + // { // $this->translatableStringHelper = $translatableStringHelper; // } @@ -33,7 +35,7 @@ final class LocationType extends AbstractType ->add('locationType', EntityType::class, [ 'class' => EntityLocationType::class, 'choice_label' => function (EntityLocationType $entity) { - //return $this->translatableStringHelper->localize($entity->getTitle()); + //return $this->translatableStringHelper->localize($entity->getTitle()); //TODO not working. Cannot pass smthg in the constructor return $entity->getTitle()['fr']; }, ]) @@ -44,4 +46,24 @@ final class LocationType extends AbstractType 'mapped' => false, ]); } + + + /** + * @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'; + } + } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Location/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Location/index.html.twig index a99311a9c..37a520338 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Location/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Location/index.html.twig @@ -7,10 +7,10 @@ {{ 'Name'|trans }} - {{ 'phonenumber1'|trans }} - {{ 'phonenumber2'|trans }} - {{ 'email'|trans }} - {{ 'address'|trans }} + {{ 'Phonenumber1'|trans }} + {{ 'Phonenumber2'|trans }} + {{ 'Email'|trans }} + {{ 'Address'|trans }} diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index f7c65b234..e5243eae0 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -138,6 +138,10 @@ services: autoconfigure: true autowire: true - Chill\MainBundle\Form\Type\LocationType: + Chill\MainBundle\Form\Type\LocationFormType: autowire: true - autoconfigure: true \ No newline at end of file + autoconfigure: true + arguments: + - "@chill.main.helper.translatable_string" + tags: + - { name: form.type } \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 24249053e..01e24044d 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -191,6 +191,9 @@ required: requis never: jamais Create a new location: Créer une nouvelle localisation Location list: Liste des localisations +Location type: Type de localisation +Phonenumber1: Numéro de téléphone +Phonenumber2: Autre numéro de téléphone # circles / scopes Choose the circle: Choisir le cercle