protected function newAjaxAction()
    {
        $this->dispatch(EasyAdminEvents::PRE_NEW);

        $entity = $this->executeDynamicMethod('createNew<EntityName>Entity');
        $easyadmin = \array_merge($this->request->attributes->get('easyadmin'), ['item' => $entity]);
        $this->request->attributes->set('easyadmin', $easyadmin);

        $fields = $this->entity['new']['fields'];
        $newForm = $this->executeDynamicMethod('create<EntityName>NewForm', [$entity, $fields]);
        $newForm->handleRequest($this->request);
        if ($newForm->isSubmitted() && $newForm->isValid()) {
            $this->dispatch(EasyAdminEvents::PRE_PERSIST, ['entity' => $entity]);
            $this->executeDynamicMethod('persist<EntityName>Entity', [$entity]);
            $this->dispatch(EasyAdminEvents::POST_PERSIST, ['entity' => $entity]);

            return new JsonResponse(['option' => ['id' => $entity->getId(), 'text' => (string) $entity]]);
        }

        $this->dispatch(EasyAdminEvents::POST_NEW, ['entity_fields' => $fields, 'form' => $newForm, 'entity' => $entity]);

        $parameters = ['form' => $newForm->createView(), 'entity_fields' => $fields, 'entity' => $entity];
        $templatePath = '@EasyAdminExtension/default/new_ajax.html.twig';
        if (isset($this->entity['templates']['new_ajax'])) {
            $templatePath = $this->entity['templates']['new_ajax'];
        }

        return new JsonResponse(['html' => $this->renderView($templatePath, $parameters)]);
    }
protected function newAjaxAction()
    {
        $this->dispatch(EasyAdminEvents::PRE_NEW);

        $entity = $this->executeDynamicMethod('createNew<EntityName>Entity');
        $easyadmin = \array_merge($this->request->attributes->get('easyadmin'), ['item' => $entity]);
        $this->request->attributes->set('easyadmin', $easyadmin);

        $fields = $this->entity['new']['fields'];
        $newForm = $this->executeDynamicMethod('create<EntityName>NewForm', [$entity, $fields]);
        $newForm->handleRequest($this->request);
        if ($newForm->isSubmitted() && $newForm->isValid()) {
            $this->dispatch(EasyAdminEvents::PRE_PERSIST, ['entity' => $entity]);
            $this->executeDynamicMethod('persist<EntityName>Entity', [$entity]);
            $this->dispatch(EasyAdminEvents::POST_PERSIST, ['entity' => $entity]);

            return new JsonResponse(['option' => ['id' => $entity->getId(), 'text' => (string) $entity]]);
        }

        $this->dispatch(EasyAdminEvents::POST_NEW, ['entity_fields' => $fields, 'form' => $newForm, 'entity' => $entity]);

        $parameters = ['form' => $newForm->createView(), 'entity_fields' => $fields, 'entity' => $entity];
        $templatePath = '@EasyAdminExtension/default/new_ajax.html.twig';
        if (isset($this->entity['templates']['new_ajax'])) {
            $templatePath = $this->entity['templates']['new_ajax'];
        }

        return new JsonResponse(['html' => $this->renderView($templatePath, $parameters)]);
    }
protected function newAjaxAction ( ) { $ this -> dispatch ( EasyAdminEvents :: PRE_NEW ) ; $ entity = $ this -> executeDynamicMethod ( 'createNew<EntityName>Entity' ) ; $ easyadmin = \ array_merge ( $ this -> request -> attributes -> get ( 'easyadmin' ) , [ 'item' => $ entity ] ) ; $ this -> request -> attributes -> set ( 'easyadmin' , $ easyadmin ) ; $ fields = $ this -> entity [ 'new' ] [ 'fields' ] ; $ newForm = $ this -> executeDynamicMethod ( 'create<EntityName>NewForm' , [ $ entity , $ fields ] ) ; $ newForm -> handleRequest ( $ this -> request ) ; if ( $ newForm -> isSubmitted ( ) && $ newForm -> isValid ( ) ) { $ this -> dispatch ( EasyAdminEvents :: PRE_PERSIST , [ 'entity' => $ entity ] ) ; $ this -> executeDynamicMethod ( 'persist<EntityName>Entity' , [ $ entity ] ) ; $ this -> dispatch ( EasyAdminEvents :: POST_PERSIST , [ 'entity' => $ entity ] ) ; return new JsonResponse ( [ 'option' => [ 'id' => $ entity -> getId ( ) , 'text' => ( string ) $ entity ] ] ) ; } $ this -> dispatch ( EasyAdminEvents :: POST_NEW , [ 'entity_fields' => $ fields , 'form' => $ newForm , 'entity' => $ entity ] ) ; $ parameters = [ 'form' => $ newForm -> createView ( ) , 'entity_fields' => $ fields , 'entity' => $ entity ] ; $ templatePath = '@EasyAdminExtension/default/new_ajax.html.twig' ; if ( isset ( $ this -> entity [ 'templates' ] [ 'new_ajax' ] ) ) { $ templatePath = $ this -> entity [ 'templates' ] [ 'new_ajax' ] ; } return new JsonResponse ( [ 'html' => $ this -> renderView ( $ templatePath , $ parameters ) ] ) ; }
The method that is executed when the user performs a 'new ajax' action on an entity.

@return JsonResponse
The method that is executed when the user performs a new ajax action on an entity .