Beispiel #1
0
 /**
  * Edit and Saves pack
  *
  * @param FormInterface $form    Form
  * @param PackInterface $pack    Pack
  * @param boolean       $isValid Is valid
  *
  * @return RedirectResponse Redirect response
  *
  * @Route(
  *      path = "/{id}",
  *      name = "admin_purchasable_pack_view",
  *      requirements = {
  *          "id" = "\d+",
  *      },
  *      methods = {"GET"}
  * )
  * @Route(
  *      path = "/{id}/edit",
  *      name = "admin_purchasable_pack_edit",
  *      requirements = {
  *          "id" = "\d+",
  *      },
  *      methods = {"GET"}
  * )
  * @Route(
  *      path = "/{id}/update",
  *      name = "admin_purchasable_pack_update",
  *      requirements = {
  *          "id" = "\d+",
  *      },
  *      methods = {"POST"}
  * )
  *
  * @Route(
  *      path = "/new",
  *      name = "admin_purchasable_pack_new",
  *      methods = {"GET"}
  * )
  * @Route(
  *      path = "/new/update",
  *      name = "admin_purchasable_pack_save",
  *      methods = {"POST"}
  * )
  *
  * @EntityAnnotation(
  *      class = {
  *          "factory" = "elcodi.factory.purchasable_pack",
  *          "method" = "create",
  *          "static" = false
  *      },
  *      mapping = {
  *          "id" = "~id~"
  *      },
  *      mappingFallback = true,
  *      name = "pack",
  *      persist = true
  * )
  * @FormAnnotation(
  *      class = "elcodi_admin_product_form_type_purchasable_pack",
  *      name  = "form",
  *      entity = "pack",
  *      handleRequest = true,
  *      validate = "isValid"
  * )
  *
  * @Template
  */
 public function editAction(FormInterface $form, PackInterface $pack, $isValid)
 {
     if ($isValid) {
         $firstImage = $pack->getSortedImages()->first();
         if ($firstImage instanceof ImageInterface) {
             $pack->setPrincipalImage($firstImage);
         }
         $this->flush($pack);
         $this->addFlash('success', $this->get('translator')->trans('admin.purchasable_pack.saved'));
         return $this->redirectToRoute('admin_purchasable_pack_list');
     }
     return ['pack' => $pack, 'form' => $form->createView()];
 }
 /**
  * Resolve name for pack.
  *
  * @param PackInterface $pack Pack
  *
  * @return string Resolve pack name
  */
 private function resolvePackName(PackInterface $pack)
 {
     return $pack->getName();
 }