src/Sulu/Bundle/SnippetBundle/Controller/SnippetController.php
public function postTriggerAction($id, Request $request)
    {
        $view = null;
        $snippet = null;

        $locale = $this->getLocale($request);
        $action = $this->getRequestParameter($request, 'action', true);

        try {
            switch ($action) {
                case 'copy-locale':
                    $destLocales = explode(',', $this->getRequestParameter($request, 'dest', true));

                    // call repository method
                    $snippet = $this->snippetRepository->copyLocale(
                        $id,
                        $this->getUser()->getId(),
                        $locale,
                        $destLocales
                    );

                    // publish the snippet in every dest locale, otherwise it's not in the live workspace.
                    foreach ($destLocales as $destLocale) {
                        $destSnippet = $this->findDocument($id, $destLocale);
                        $this->documentManager->publish($destSnippet, $destLocale);
                    }

                    // flush all published snippets
                    $this->documentManager->flush();

                    break;
                default:
                    throw new RestException('Unrecognized action: ' . $action);
            }

            // prepare view
            $view = View::create(
                $this->decorateSnippet($snippet->toArray(), $locale),
                null !== $snippet ? 200 : 204
            );
        } catch (RestException $exc) {
            $view = View::create($exc->toArray(), 400);
        }

        return $this->viewHandler->handle($view);
    }
public function postTriggerAction($id, Request $request)
    {
        $view = null;
        $snippet = null;

        $locale = $this->getLocale($request);
        $action = $this->getRequestParameter($request, 'action', true);

        try {
            switch ($action) {
                case 'copy-locale':
                    $destLocales = explode(',', $this->getRequestParameter($request, 'dest', true));

                    // call repository method
                    $snippet = $this->snippetRepository->copyLocale(
                        $id,
                        $this->getUser()->getId(),
                        $locale,
                        $destLocales
                    );

                    // publish the snippet in every dest locale, otherwise it's not in the live workspace.
                    foreach ($destLocales as $destLocale) {
                        $destSnippet = $this->findDocument($id, $destLocale);
                        $this->documentManager->publish($destSnippet, $destLocale);
                    }

                    // flush all published snippets
                    $this->documentManager->flush();

                    break;
                default:
                    throw new RestException('Unrecognized action: ' . $action);
            }

            // prepare view
            $view = View::create(
                $this->decorateSnippet($snippet->toArray(), $locale),
                null !== $snippet ? 200 : 204
            );
        } catch (RestException $exc) {
            $view = View::create($exc->toArray(), 400);
        }

        return $this->viewHandler->handle($view);
    }
public function postTriggerAction ( $ id , Request $ request ) { $ view = null ; $ snippet = null ; $ locale = $ this -> getLocale ( $ request ) ; $ action = $ this -> getRequestParameter ( $ request , 'action' , true ) ; try { switch ( $ action ) { case 'copy-locale' : $ destLocales = explode ( ',' , $ this -> getRequestParameter ( $ request , 'dest' , true ) ) ; // call repository method $ snippet = $ this -> snippetRepository -> copyLocale ( $ id , $ this -> getUser ( ) -> getId ( ) , $ locale , $ destLocales ) ; // publish the snippet in every dest locale, otherwise it's not in the live workspace. foreach ( $ destLocales as $ destLocale ) { $ destSnippet = $ this -> findDocument ( $ id , $ destLocale ) ; $ this -> documentManager -> publish ( $ destSnippet , $ destLocale ) ; } // flush all published snippets $ this -> documentManager -> flush ( ) ; break ; default : throw new RestException ( 'Unrecognized action: ' . $ action ) ; } // prepare view $ view = View :: create ( $ this -> decorateSnippet ( $ snippet -> toArray ( ) , $ locale ) , null !== $ snippet ? 200 : 204 ) ; } catch ( RestException $ exc ) { $ view = View :: create ( $ exc -> toArray ( ) , 400 ) ; } return $ this -> viewHandler -> handle ( $ view ) ; }
trigger a action for given snippet specified over get-action parameter.

@Post("/snippets/{id}")

@param string $id
@param Request $request

@return \Symfony\Component\HttpFoundation\Response
trigger a action for given snippet specified over get - action parameter .