vendor/wearemarketing/webcontentbundle/Controller/EditInlineController.php line 42

Open in your IDE?
  1. <?php
  2. namespace WAM\Bundle\WebContentBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\HttpFoundation\Response;
  5. /**
  6.  * @author Edgar Tébar <etebar@wearemarketing.com>
  7.  */
  8. class EditInlineController extends Controller
  9. {
  10.     const NEW_MESSAGE_INPUT_NAME 'new_message';
  11.     const TEMPLATE_EDIT_INLINE_FORM 'WAMWebContentBundle:EditInline:edit_inline_translation.html.twig';
  12.     const TEMPLATE_TRANS_LINK_ADMIN 'WAMWebContentBundle:EditInline:path_to_admin_translation.html.twig';
  13.     const TEMPLATE_EDIT_INLINE_FULL_PATH 'WAMWebContentBundle:EditInline:full_edit_path_template.html.twig';
  14.     public function updateTranslationAction($id)
  15.     {
  16.         $request $this->container->get('request_stack')->getCurrentRequest();
  17.         $locale $request->get('_locale');
  18.         $transUnit $this->getDoctrine()->getRepository('LexikTranslationBundle:TransUnit')->findOneById($id);
  19.         $transUnitManager $this->container->get('lexik_translation.trans_unit.manager');
  20.         $newMessage $request->get(self::NEW_MESSAGE_INPUT_NAME);
  21.         $transUnitManager->updateTranslation(
  22.             $transUnit,
  23.             $locale,
  24.             $newMessage,
  25.             true
  26.         );
  27.         $this->clearCache();
  28.         return new Response($newMessage);
  29.     }
  30.     public function fullAdminEditAction($route ''$aditionalClass ''$title ''$faIconClass ''$parentClass '')
  31.     {
  32.         $response $this->render(self::TEMPLATE_EDIT_INLINE_FULL_PATH, array(
  33.             'route' => $route,
  34.             'aditional_class' => $aditionalClass,
  35.             'title' => $title,
  36.             'fa_icon_class' => $faIconClass,
  37.             'parent_class' => $parentClass,
  38.         ));
  39.         $response->setPrivate();
  40.         return $response;
  41.     }
  42.     public function adminBarAction($id$class)
  43.     {
  44.         $object $this->getEntityManager()->find($class$id);
  45.         $response $this->render('WAMWebContentBundle:EditInline:admin_bar.html.twig', array(
  46.             'object' => $object,
  47.         ));
  48.         $response->setPrivate();
  49.         return $response;
  50.     }
  51.     public function renderFormAction($trans ''$message '')
  52.     {
  53.         $object $this->getEntityManager()->getRepository('LexikTranslationBundle:TransUnit')
  54.             ->findOneByKey($message);
  55.         $response $this->render(self::TEMPLATE_EDIT_INLINE_FORM, array(
  56.             'trans' => $trans,
  57.             'message' => $message,
  58.             'object' => $object,
  59.         ));
  60.         $response->setPrivate();
  61.         return $response;
  62.     }
  63.     public function clearCacheAction()
  64.     {
  65.         $this->clearCache();
  66.         return new Response('cache_clear');
  67.     }
  68.     protected function getManagedLocales()
  69.     {
  70.         return $this->container->getParameter('lexik_translation.managed_locales');
  71.     }
  72.     private function getEntityManager()
  73.     {
  74.         return $this->get('doctrine.orm.default_entity_manager');
  75.     }
  76.     private function clearCache()
  77.     {
  78.         $this->get('translator')->removeLocalesCacheFiles($this->getManagedLocales());
  79.     }
  80. }