Exemplo n.º 1
0
 /**
  * @param Request $request
  * @param boolean $enabled
  *
  * @return RedirectResponse|Response
  */
 protected function toggle(Request $request, $enabled)
 {
     $this->isGrantedOr403('update');
     $resource = $this->findOr404($request);
     $resource->setEnabled($enabled);
     $this->domainManager->update($resource, $enabled ? 'enable' : 'disable');
     if ($this->config->isApiRequest()) {
         if ($resource instanceof ResourceEvent) {
             throw new HttpException($resource->getErrorCode(), $resource->getMessage());
         }
         return $this->handleView($this->view($resource, 204));
     }
     return $this->redirectHandler->redirectToIndex();
 }
Exemplo n.º 2
0
 public function updateStateAction(Request $request, $transition, $graph = null)
 {
     $resource = $this->findOr404($request);
     if (null === $graph) {
         $graph = $this->stateMachineGraph;
     }
     $stateMachine = $this->get('sm.factory')->get($resource, $graph);
     if (!$stateMachine->can($transition)) {
         throw new NotFoundHttpException(sprintf('The requested transition %s cannot be applied on the given %s with graph %s.', $transition, $this->config->getResourceName(), $graph));
     }
     $stateMachine->apply($transition);
     $this->domainManager->update($resource);
     return $this->redirectHandler->redirectToReferer();
 }