/**
  * Creates and processes the form to add a new Entity
  *
  * @param AbstractAdminListConfigurator $configurator The adminlist configurator
  * @param string                        $type         The type to add
  * @param null|Request                  $request
  *
  * @throws AccessDeniedHttpException
  *
  * @return array
  */
 protected function doAddAction(AbstractAdminListConfigurator $configurator, $type = null, Request $request = null)
 {
     if (!$configurator->canAdd()) {
         throw new AccessDeniedHttpException('You do not have sufficient rights to access this page.');
     }
     /* @var EntityManager $em */
     $em = $this->getEntityManager();
     if (is_null($request)) {
         $request = $this->getRequest();
     }
     $entityName = null;
     if (isset($type)) {
         $entityName = $type;
     } else {
         $entityName = $configurator->getRepositoryName();
     }
     $classMetaData = $em->getClassMetadata($entityName);
     // Creates a new instance of the mapped class, without invoking the constructor.
     $classname = $classMetaData->getName();
     $helper = new $classname();
     $helper = $configurator->decorateNewEntity($helper);
     $form = $this->createForm($configurator->getAdminType($helper), $helper);
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $em->persist($helper);
             $em->flush();
             $indexUrl = $configurator->getIndexUrl();
             return new RedirectResponse($this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array()));
         }
     }
     return new Response($this->renderView($configurator->getAddTemplate(), array('form' => $form->createView(), 'adminlistconfigurator' => $configurator)));
 }
 /**
  * Creates and processes the form to add a new Entity
  *
  * @param AbstractAdminListConfigurator $configurator The adminlist configurator
  * @param string                        $type         The type to add
  * @param null|Request                  $request
  *
  * @throws AccessDeniedHttpException
  *
  * @return array
  */
 protected function doAddAction(AbstractAdminListConfigurator $configurator, $type = null, Request $request = null)
 {
     if (!$configurator->canAdd()) {
         throw new AccessDeniedHttpException('You do not have sufficient rights to access this page.');
     }
     /* @var EntityManager $em */
     $em = $this->getEntityManager();
     if (is_null($request)) {
         $request = $this->getRequest();
     }
     $entityName = null;
     if (isset($type)) {
         $entityName = $type;
     } else {
         $entityName = $configurator->getRepositoryName();
     }
     $classMetaData = $em->getClassMetadata($entityName);
     // Creates a new instance of the mapped class, without invoking the constructor.
     $classname = $classMetaData->getName();
     $helper = new $classname();
     $helper = $configurator->decorateNewEntity($helper);
     $formType = $configurator->getAdminType($helper);
     if (!is_object($formType) && is_string($formType)) {
         $formType = $this->container->get($formType);
     }
     $event = new AdaptSimpleFormEvent($request, $formType, $helper);
     $event = $this->container->get('event_dispatcher')->dispatch(Events::ADAPT_SIMPLE_FORM, $event);
     $tabPane = $event->getTabPane();
     $form = $this->createForm($formType, $helper);
     if ($request->isMethod('POST')) {
         if ($tabPane) {
             $tabPane->bindRequest($request);
             $form = $tabPane->getForm();
         } else {
             $form->submit($request);
         }
         if ($form->isValid()) {
             $em->persist($helper);
             $em->flush();
             $indexUrl = $configurator->getIndexUrl();
             return new RedirectResponse($this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array()));
         }
     }
     $params = array('form' => $form->createView(), 'adminlistconfigurator' => $configurator);
     if ($tabPane) {
         $params = array_merge($params, array('tabPane' => $tabPane));
     }
     return new Response($this->renderView($configurator->getAddTemplate(), $params));
 }