public function createAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $refFolder = $this->findFolderById($request->attributes->get('id'));
        $repo = $this->getFolderRepository();

        $newFolder = $repo->createNew();
        $newFolder->setName('New folder');

        $mode = strtolower($request->request->get('mode'));
        if (!in_array($mode, array('child', 'after'))) {
            $response = new Response(json_encode(array(
                'error'   => true,
                'message' => 'Unexpected creation mode.',
            ), JSON_FORCE_OBJECT));
        } else {
            if ($mode === 'after') {
                $repo->persistAsNextSiblingOf($newFolder, $refFolder);
            } else {
                $repo->persistAsFirstChildOf($newFolder, $refFolder);
            }

            if (true !== $message = $this->validateFolder($newFolder)) {
                $response = new Response(json_encode(array(
                    'error'   => true,
                    'message' => $message,
                ), JSON_FORCE_OBJECT));
            } else {
                $this->getEntityManager()->flush();
                $data = $this->get('jms_serializer')->serialize(
                    $newFolder,
                    'json',
                    SerializationContext::create()->setGroups(array('Manager'))
                );
                $response = new Response(sprintf('{"node":%s}', $data));
            }
        }

        $response->headers->add(array('Content-Type' => 'application/json'));
        return $response;
    }
public function createAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $refFolder = $this->findFolderById($request->attributes->get('id'));
        $repo = $this->getFolderRepository();

        $newFolder = $repo->createNew();
        $newFolder->setName('New folder');

        $mode = strtolower($request->request->get('mode'));
        if (!in_array($mode, array('child', 'after'))) {
            $response = new Response(json_encode(array(
                'error'   => true,
                'message' => 'Unexpected creation mode.',
            ), JSON_FORCE_OBJECT));
        } else {
            if ($mode === 'after') {
                $repo->persistAsNextSiblingOf($newFolder, $refFolder);
            } else {
                $repo->persistAsFirstChildOf($newFolder, $refFolder);
            }

            if (true !== $message = $this->validateFolder($newFolder)) {
                $response = new Response(json_encode(array(
                    'error'   => true,
                    'message' => $message,
                ), JSON_FORCE_OBJECT));
            } else {
                $this->getEntityManager()->flush();
                $data = $this->get('jms_serializer')->serialize(
                    $newFolder,
                    'json',
                    SerializationContext::create()->setGroups(array('Manager'))
                );
                $response = new Response(sprintf('{"node":%s}', $data));
            }
        }

        $response->headers->add(array('Content-Type' => 'application/json'));
        return $response;
    }
public function createAction ( Request $ request ) { if ( ! $ request -> isXmlHttpRequest ( ) ) { throw new NotFoundHttpException ( ) ; } $ refFolder = $ this -> findFolderById ( $ request -> attributes -> get ( 'id' ) ) ; $ repo = $ this -> getFolderRepository ( ) ; $ newFolder = $ repo -> createNew ( ) ; $ newFolder -> setName ( 'New folder' ) ; $ mode = strtolower ( $ request -> request -> get ( 'mode' ) ) ; if ( ! in_array ( $ mode , array ( 'child' , 'after' ) ) ) { $ response = new Response ( json_encode ( array ( 'error' => true , 'message' => 'Unexpected creation mode.' , ) , JSON_FORCE_OBJECT ) ) ; } else { if ( $ mode === 'after' ) { $ repo -> persistAsNextSiblingOf ( $ newFolder , $ refFolder ) ; } else { $ repo -> persistAsFirstChildOf ( $ newFolder , $ refFolder ) ; } if ( true !== $ message = $ this -> validateFolder ( $ newFolder ) ) { $ response = new Response ( json_encode ( array ( 'error' => true , 'message' => $ message , ) , JSON_FORCE_OBJECT ) ) ; } else { $ this -> getEntityManager ( ) -> flush ( ) ; $ data = $ this -> get ( 'jms_serializer' ) -> serialize ( $ newFolder , 'json' , SerializationContext :: create ( ) -> setGroups ( array ( 'Manager' ) ) ) ; $ response = new Response ( sprintf ( '{"node":%s}' , $ data ) ) ; } } $ response -> headers -> add ( array ( 'Content-Type' => 'application/json' ) ) ; return $ response ; }
Creates the folder.

@param Request $request

@return Response
Creates the folder .