+ //Fetch locations
+ //XXX: we want to display all active locations anyway
+ $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period, $id);
+
+ //Create snippet forms for role_guest
+ if ($this->isGranted('ROLE_GUEST')) {
+ //Fetch all user snippet
+ $snippets = $doctrine->getRepository(Snippet::class)->findByLocaleUserId($request->getLocale(), $id);
+
+ //Rekey by location id
+ $snippets = array_reduce($snippets, function($carry, $item){$carry[$item->getLocation()->getId()] = $item; return $carry;}, []);
+
+ //Init snippets to context
+ $this->context['forms']['snippets'] = [];
+
+ //Iterate on locations
+ foreach($locations as $locationId => $location) {
+ //Init snippet
+ $snippet = new Snippet();
+
+ //Set default locale
+ $snippet->setLocale($request->getLocale());
+
+ //Set default user
+ $snippet->setUser($user);
+
+ //Set default location
+ $snippet->setLocation($doctrine->getRepository(Location::class)->findOneById($locationId));
+
+ //Get snippet
+ if (!empty($snippets[$locationId])) {
+ $snippet = $snippets[$locationId];
+ }
+
+ //Create SnippetType form
+ #$form = $this->createForm('Rapsys\AirBundle\Form\SnippetType', $snippet, [
+ $form = $this->container->get('form.factory')->createNamed('snipped_'.$request->getLocale().'_'.$locationId, 'Rapsys\AirBundle\Form\SnippetType', $snippet, [
+ //Set the action
+ //TODO: voir si on peut pas faire sauter ça ici
+ 'action' =>
+ !empty($snippet->getId()) ?
+ $this->generateUrl('rapsys_air_snippet_edit', ['id' => $snippet->getId()]) :
+ $this->generateUrl('rapsys_air_snippet_add', ['location' => $locationId]),
+ #'action' => $this->generateUrl('rapsys_air_snippet_add'),
+ //Set the form attribute
+ 'attr' => [],
+ //Set csrf_token_id
+ //TODO: would maybe need a signature field
+ //'csrf_token_id' => $request->getLocale().'_'.$id.'_'.$locationId
+ ]);
+ #return $this->container->get('form.factory')->create($type, $data, $options);
+ #public function createNamed($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
+
+ //Add form to context
+ $this->context['forms']['snippets'][$locationId] = $form->createView();
+ }
+ }
+