public function testInitialState() { $this->assertSame($this->resource, $this->event->getResource()); $this->assertSame($this->form, $this->event->getForm()); $this->assertSame($this->statusCode, $this->event->getStatusCode()); $this->assertNull($this->event->getView()); }
/** * @param ActionEvent $event */ public function onAction(ActionEvent $event) { if ($this->getParameterResolver()->resolveApi()) { return; } $form = $event->getForm(); if ($form !== null && !$form->isValid()) { $view = View::create($form); } else { $route = $this->getParameterResolver()->resolveRedirectRoute(); $routeParameters = []; if ($form !== null) { $routeParameters = $this->getParameterResolver()->resolveRedirectRouteParameters(is_object($data = $form->getData()) ? $data : null, $this->getParameterResolver()->resolveRedirectRouteParametersForward()); } $view = View::createRouteRedirect($route, $routeParameters); } $event->setView($view); }
/** * @param ActionEvent $event */ public function onAction(ActionEvent $event) { if (!$this->getParameterResolver()->resolveApi()) { return; } $form = $event->getForm(); if ($form === null) { $view = View::create(); } elseif (!$form->isValid()) { $view = View::create($form, Response::HTTP_BAD_REQUEST); } else { $headers = []; $statusCode = $event->getStatusCode(); $data = $statusCode === Response::HTTP_NO_CONTENT ? null : $form->getData(); if ($statusCode === Response::HTTP_CREATED) { $headers['Location'] = $this->urlGenerator->generate($this->getParameterResolver()->resolveLocationRoute(), $this->getParameterResolver()->resolveLocationRouteParameters($form->getData())); } $view = View::create($data, $statusCode, $headers); } $event->setView($view); }