public function generateAndAddNodeAction(Request $request) { $this->validateAccessForRole('ROLE_ACCESS_NODES'); try { $generator = new UniqueNodeGenerator($this->getService('em')); $source = $generator->generateFromRequest($request); /* * Dispatch event */ $event = new FilterNodeEvent($source->getNode()); $this->getService('dispatcher')->dispatch(NodeEvents::NODE_CREATED, $event); return $this->redirect($this->generateUrl('nodesEditSourcePage', ['nodeId' => $source->getNode()->getId(), 'translationId' => $translation->getId()])); } catch (\Exception $e) { $msg = $this->getTranslator()->trans('node.noCreation.alreadyExists'); return $this->throw404($msg); } return $this->throw404($this->getTranslator()->trans('bad.request')); }
public function quickAddAction(Request $request) { /* * Validate */ if (true !== ($notValid = $this->validateRequest($request))) { return new Response(json_encode($notValid), Response::HTTP_FORBIDDEN, ['content-type' => 'application/javascript']); } $this->validateAccessForRole('ROLE_ACCESS_NODES'); $responseArray = []; try { $generator = new UniqueNodeGenerator($this->getService('em')); $source = $generator->generateFromRequest($request); /* * Dispatch event */ $event = new FilterNodeEvent($source->getNode()); $this->getService('dispatcher')->dispatch(NodeEvents::NODE_CREATED, $event); $responseArray = ['statusCode' => Response::HTTP_OK, 'status' => 'success', 'responseText' => $this->getTranslator()->trans('added.node.%name%', ['%name%' => $source->getTitle()])]; } catch (\Exception $e) { $msg = $this->getTranslator()->trans($e->getMessage()); $responseArray = ['statusCode' => Response::HTTP_FORBIDDEN, 'status' => 'danger', 'responseText' => $msg]; } return new Response(json_encode($responseArray), $responseArray['statusCode'], ['content-type' => 'application/javascript']); }