Esempio n. 1
0
 /**
  * @param  Request $request
  * @param  Block $block
  * @param  int $id
  * @return RedirectResponse|Response
  */
 public function newLinkAction(Request $request, Block $block, $id = 0)
 {
     $data = [];
     $em = $this->getDoctrine()->getManager();
     $BlockLink = $id ? $em->find('OjsSiteBundle:BlockLink', $id) : new BlockLink();
     $form = $this->createForm(new BlockLinkType(), $BlockLink, ['block_id' => $block->getId()]);
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $BlockLink->setBlock($block);
             $em->persist($BlockLink);
             $block->addLink($BlockLink);
             $em->persist($block);
             $em->flush();
             $journal = $em->getRepository('OjsJournalBundle:Journal')->find($block->getObjectId());
             return $this->redirect($this->get('ojs.journal_service')->generateUrl($journal));
         }
         $this->get('session')->getFlashBag()->add('error', 'All fields are required');
     }
     $data['form'] = $form->createView();
     return $this->render('OjsSiteBundle:BlockLink:create.html.twig', $data);
 }