/** * @throws NotImplementedException If Content is missing location as this is not supported in current version */ public function previewContentAction(Request $request, $contentId, $versionNo, $language, $siteAccessName = null) { $this->previewHelper->setPreviewActive(true); try { $content = $this->contentService->loadContent($contentId, array($language), $versionNo); $location = $this->locationProvider->loadMainLocation($contentId); if (!$location instanceof Location) { throw new NotImplementedException("Preview for content without locations"); } $this->previewHelper->setPreviewedContent($content); $this->previewHelper->setPreviewedLocation($location); } catch (UnauthorizedException $e) { throw new AccessDeniedException(); } if (!$this->authorizationChecker->isGranted(new AuthorizationAttribute('content', 'versionread', array('valueObject' => $content)))) { throw new AccessDeniedException(); } $siteAccess = $this->previewHelper->getOriginalSiteAccess(); // Only switch if $siteAccessName is set and different from original if ($siteAccessName !== null && $siteAccessName !== $siteAccess->name) { $siteAccess = $this->previewHelper->changeConfigScope($siteAccessName); } $response = $this->kernel->handle($this->getForwardRequest($location, $content, $siteAccess, $request), HttpKernelInterface::SUB_REQUEST); $response->headers->remove('cache-control'); $response->headers->remove('expires'); $this->previewHelper->restoreConfigScope(); $this->previewHelper->setPreviewActive(false); return $response; }
public function testGetPreviewLocationNoLocation() { $contentId = 123; $contentInfo = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo')->setConstructorArgs(array(array('id' => $contentId)))->getMockForAbstractClass(); $this->contentService->expects($this->once())->method('loadContentInfo')->with($contentId)->will($this->returnValue($contentInfo)); $this->locationHandler->expects($this->once())->method('loadParentLocationsForDraftContent')->with($contentId)->will($this->returnValue(array())); $this->locationHandler->expects($this->never())->method('loadLocation'); $this->assertNull($this->provider->loadMainLocation($contentId)); }