original_string: public function newAction(Request $request)
      {
          $entity = new Plan();
          $form = $this->createForm('EcommerceBundle\Form\PlanType', $entity);
          $form->handleRequest($request);
  
          if ($form->isSubmitted() && $form->isValid()) {
              $em = $this->getDoctrine()->getManager();
              $em->persist($entity);
              
              $checkoutManager = $this->get('checkout_manager');
              $checkoutManager->createPaypalPlan($entity);
              $checkoutManager->activePaypalPlan($entity);
              
              //if come from popup
              if ($request->isXMLHttpRequest()) {         
                  return new JsonResponse(array(
                              'id' => $entity->getId(), 
                              'name' => $entity->getName()
                          ));
              }
              
              $this->get('session')->getFlashBag()->add('success', 'plan.created');
  
              return $this->redirectToRoute('ecommerce_plan_show', array('id' => $entity->getId()));
          }
  
          return array(
              'entity' => $entity,
              'form' => $form->createView(),
          );
      }
code: public function newAction(Request $request)
      {
          $entity = new Plan();
          $form = $this->createForm('EcommerceBundle\Form\PlanType', $entity);
          $form->handleRequest($request);
  
          if ($form->isSubmitted() && $form->isValid()) {
              $em = $this->getDoctrine()->getManager();
              $em->persist($entity);
              
              $checkoutManager = $this->get('checkout_manager');
              $checkoutManager->createPaypalPlan($entity);
              $checkoutManager->activePaypalPlan($entity);
              
              //if come from popup
              if ($request->isXMLHttpRequest()) {         
                  return new JsonResponse(array(
                              'id' => $entity->getId(), 
                              'name' => $entity->getName()
                          ));
              }
              
              $this->get('session')->getFlashBag()->add('success', 'plan.created');
  
              return $this->redirectToRoute('ecommerce_plan_show', array('id' => $entity->getId()));
          }
  
          return array(
              'entity' => $entity,
              'form' => $form->createView(),
          );
      }
code_tokens: public function newAction ( Request $ request ) { $ entity = new Plan ( ) ; $ form = $ this -> createForm ( 'EcommerceBundle\Form\PlanType' , $ entity ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ entity ) ; $ checkoutManager = $ this -> get ( 'checkout_manager' ) ; $ checkoutManager -> createPaypalPlan ( $ entity ) ; $ checkoutManager -> activePaypalPlan ( $ entity ) ; //if come from popup if ( $ request -> isXMLHttpRequest ( ) ) { return new JsonResponse ( array ( 'id' => $ entity -> getId ( ) , 'name' => $ entity -> getName ( ) ) ) ; } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'plan.created' ) ; return $ this -> redirectToRoute ( 'ecommerce_plan_show' , array ( 'id' => $ entity -> getId ( ) ) ) ; } return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ; }
docstring: Creates a new Plan entity.
  
  @Route("/new")
  @Method({"GET", "POST"})
  @Template()
docstring_tokens: Creates a new Plan entity .