Example #1
0
 /**
  * @Route("/food-opening/{slug}")
  * @Template("CraftLocationBundle:Edit:edit.html.twig")
  */
 public function foodOpeningAction(Location $location, Request $request)
 {
     if ($location->getFood() === null) {
         $location->setFood(new Food());
     }
     if ($location->getFood()->getKitchenOpening() === null) {
         $location->getFood()->setKitchenOpening(new OpeningTimes());
     }
     $form = $this->createForm(new OpeningTimesType(), $location->getFood()->getKitchenOpening());
     $form->handleRequest($request);
     if ($form->get('remove')->isClicked()) {
         $location->getFood()->setKitchenOpening(null);
         $this->get('location_service')->updateLocation($location, $this->getUser(), $request);
         return $this->redirectToView($location);
     }
     if ($form->isValid()) {
         $this->get('location_service')->updateLocation($location, $this->getUser(), $request);
         return $this->redirectToView($location);
     }
     return ['form' => $form->createView(), 'headline' => 'Kitchen Opening'];
 }