/** * @Route("/inline-edit", name="KunstmaanTranslatorBundle_settings_translations_inline_edit") * @Method({"POST"}) */ public function inlineEditAction(Request $request) { $values = $request->request->all(); $adminListConfigurator = $this->getAdminListConfigurator(); if (!$adminListConfigurator->canEditInline($values)) { throw new AccessDeniedHttpException("Not allowed to edit this translation"); } $id = isset($values['pk']) ? (int) $values['pk'] : 0; $em = $this->getDoctrine()->getManager(); /** * @var Translator $translator */ $translator = $this->get('translator'); try { if ($id !== 0) { // Find existing translation $translation = $em->getRepository('KunstmaanTranslatorBundle:Translation')->find($id); if (is_null($translation)) { return new Response($translator->trans('translator.translator.invalid_translation'), 500); } } else { // Create new translation $translation = new Translation(); $translation->setDomain($values['domain']); $translation->setKeyword($values['keyword']); $translation->setLocale($values['locale']); $translation->setTranslationId($values['translationId']); } $translation->setText($values['value']); $em->persist($translation); $em->flush(); return new JsonResponse(array('success' => true, 'uid' => $translation->getId()), 200); } catch (\Exception $e) { return new Response($translator->trans('translator.translator.fatal_error_occurred'), 500); } }
public function addTranslation(Translation $translation) { $translation->setTranslationId($this->getId()); $this->translations->add($translation); }