assign('contentObjectData', $this->configurationManager->getContentObject()->data); $view->assign('emConfiguration', GeneralUtility::makeInstance(EmConfiguration::class)); if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) { $view->assign('pageData', $GLOBALS['TSFE']->page); } parent::initializeView($view); } // /** // * @param RequestInterface $request // * @param ResponseInterface $response // * @throws \Exception // */ // public function processRequest(RequestInterface $request, ResponseInterface $response) // { // try { // parent::processRequest($request, $response); // } catch (\Exception $exception) { // $this->handleKnownExceptionsElseThrowAgain($exception); // } // } /** * @param \Exception $exception * * @throws \Exception * * @return void */ private function handleKnownExceptionsElseThrowAgain(\Exception $exception): void { $previousException = $exception->getPrevious(); if ( $this->actionMethodName === 'detailAction' && $previousException instanceof \TYPO3\CMS\Extbase\Property\Exception && isset($this->settings['detail']['errorHandling']) ) { $this->handleNoNewsFoundError($this->settings['detail']['errorHandling']); } else { throw $exception; } } /** * Error handling if no news entry is found * * @param string $configuration configuration what will be done * @throws \InvalidArgumentException */ protected function handleNoNewsFoundError($configuration): string { if (empty($configuration)) { return ''; } $options = GeneralUtility::trimExplode(',', $configuration, true); switch ($options[0]) { case 'redirectToListView': $this->redirect('list'); break; case 'redirectToPage': if (count($options) === 1 || count($options) > 3) { $msg = sprintf( 'If error handling "%s" is used, either 2 or 3 arguments, split by "," must be used', $options[0] ); throw new \InvalidArgumentException($msg); } $this->uriBuilder->reset(); $this->uriBuilder->setTargetPageUid($options[1]); $this->uriBuilder->setCreateAbsoluteUri(true); if (GeneralUtility::getIndpEnv('TYPO3_SSL')) { $this->uriBuilder->setAbsoluteUriScheme('https'); } $url = $this->uriBuilder->build(); if (isset($options[2])) { $this->redirectToUri($url, 0, (int)$options[2]); } else { $this->redirectToUri($url); } break; case 'pageNotFoundHandler': $typo3Information = GeneralUtility::makeInstance(Typo3Version::class); if ($typo3Information->getMajorVersion() === 9) { $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction($GLOBALS['TYPO3_REQUEST'], 'No news entry found.'); throw new ImmediateResponseException($response); } $message = 'No news entry found!'; $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction( $GLOBALS['TYPO3_REQUEST'], $message ); throw new ImmediateResponseException($response, 1590468229); break; case 'showStandaloneTemplate': if (isset($options[2])) { $statusCode = constant(HttpUtility::class . '::HTTP_STATUS_' . $options[2]); } else { $statusCode = HttpUtility::HTTP_STATUS_404; } HttpUtility::setResponseCode($statusCode); $this->getTypoScriptFrontendController()->set_no_cache('News record not found'); $standaloneTemplate = GeneralUtility::makeInstance(StandaloneView::class); $standaloneTemplate->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($options[1])); return $standaloneTemplate->render(); break; default: return ''; } } /** * @return TypoScriptFrontendController */ protected function getTypoScriptFrontendController(): TypoScriptFrontendController { return $GLOBALS['TSFE']; } }