src/Sulu/Bundle/TagBundle/Controller/TagController.php
public function postAction(Request $request)
    {
        $name = $request->get('name');

        try {
            if (null == $name) {
                throw new MissingArgumentException(self::$entityName, 'name');
            }

            $tag = $this->getManager()->save($this->getData($request));

            $context = new Context();
            $context->setGroups(['partialTag']);
            $view = $this->view($tag)->setContext($context);
        } catch (TagAlreadyExistsException $exc) {
            $cvExistsException = new ConstraintViolationException(
                'A tag with the name "' . $exc->getName() . '"already exists!',
                'name',
                ConstraintViolationException::EXCEPTION_CODE_NON_UNIQUE_NAME
            );
            $view = $this->view($cvExistsException->toArray(), 400);
        } catch (RestException $exc) {
            $view = $this->view($exc->toArray(), 400);
        }

        return $this->handleView($view);
    }
public function postAction(Request $request)
    {
        $name = $request->get('name');

        try {
            if (null == $name) {
                throw new MissingArgumentException(self::$entityName, 'name');
            }

            $tag = $this->getManager()->save($this->getData($request));

            $context = new Context();
            $context->setGroups(['partialTag']);
            $view = $this->view($tag)->setContext($context);
        } catch (TagAlreadyExistsException $exc) {
            $cvExistsException = new ConstraintViolationException(
                'A tag with the name "' . $exc->getName() . '"already exists!',
                'name',
                ConstraintViolationException::EXCEPTION_CODE_NON_UNIQUE_NAME
            );
            $view = $this->view($cvExistsException->toArray(), 400);
        } catch (RestException $exc) {
            $view = $this->view($exc->toArray(), 400);
        }

        return $this->handleView($view);
    }
public function postAction ( Request $ request ) { $ name = $ request -> get ( 'name' ) ; try { if ( null == $ name ) { throw new MissingArgumentException ( self :: $ entityName , 'name' ) ; } $ tag = $ this -> getManager ( ) -> save ( $ this -> getData ( $ request ) ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'partialTag' ] ) ; $ view = $ this -> view ( $ tag ) -> setContext ( $ context ) ; } catch ( TagAlreadyExistsException $ exc ) { $ cvExistsException = new ConstraintViolationException ( 'A tag with the name "' . $ exc -> getName ( ) . '"already exists!' , 'name' , ConstraintViolationException :: EXCEPTION_CODE_NON_UNIQUE_NAME ) ; $ view = $ this -> view ( $ cvExistsException -> toArray ( ) , 400 ) ; } catch ( RestException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Inserts a new tag.

@param \Symfony\Component\HttpFoundation\Request $request

@throws \Doctrine\DBAL\DBALException
@throws \Exception

@return \Symfony\Component\HttpFoundation\Response

@throws \Doctrine\DBAL\DBALException
@throws \Exception
Inserts a new tag .