public function onKernelRequest(GetResponseEvent $event)
 {
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     $request = $event->getRequest();
     $fc_form = $this->form_service->guessFcForm($request);
     if (!$fc_form instanceof FcForm) {
         return;
     }
     if ($fc_form->getAction()) {
         return;
     }
     /** @var FormInterface $form */
     $form = $this->form_service->create($fc_form);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $this->form_service->clear($fc_form, array('template' => $data['_template'], 'data' => $this->form_service->initData($data)));
         if ($fc_form->getIsAjax()) {
             return;
         }
         if ($fc_form->getMessage()) {
             $message = $fc_form->getMessage();
         } else {
             $message = $this->translator->trans('fc.message.form.is_valid', array(), 'FenrizbesFormConstructorBundle');
         }
         // TODO: Связывать сообщение с конкретной формой и подчищать старые
         $this->session->getFlashBag()->add('fc_form.success', $message);
         $response = new RedirectResponse($this->router->generate($request->get('_route'), $request->get('_route_params')));
         $event->setResponse($response);
     }
 }
 public function renderFcForm(\Twig_Environment $environment, $alias, $options = array())
 {
     $options = $this->form_service->buildOptions($options);
     if (!is_string($options['template'])) {
         throw new \Exception('Invalid template\'s name');
     }
     return $environment->render($options['template'], array('form' => $this->getFcFormView($alias, $options)));
 }