registerArgument('contentElementUid', 'int', 'The uid of a content element'); $this->registerArgument('formPersistenceIdentifier', 'string', 'The form persistence identifier for return URL', false, ''); } public function render(): string { $content = ''; $contentElementUid = $this->arguments['contentElementUid']; $contentRecord = BackendUtility::getRecord('tt_content', $contentElementUid); $request = null; if ($this->renderingContext->hasAttribute(ServerRequestInterface::class)) { $request = $this->renderingContext->getAttribute(ServerRequestInterface::class); } if (!empty($contentRecord) && $request !== null) { $backendLayout = GeneralUtility::makeInstance(BackendLayout::class, 'dummy', 'dummy', []); $pageId = (int)$contentRecord['pid']; $pageContext = $request->getAttribute('pageContext'); if (!$pageContext instanceof PageContext) { try { $pageContext = $this->pageContextFactory->createFromRequest($request, $pageId, $this->getBackendUser()); } catch (\Exception $e) { return ''; } } $manipulatedRequest = $this->getManipulatedRequestToFormEditor($request, $contentRecord); $pageLayoutContext = GeneralUtility::makeInstance( PageLayoutContext::class, $pageContext, $backendLayout, DrawingConfiguration::create($backendLayout, BackendUtility::getPagesTSconfig($pageId), PageViewMode::LayoutView), $manipulatedRequest ); $gridColumn = GeneralUtility::makeInstance(GridColumn::class, $pageLayoutContext, []); $contentRecord = $this->recordFactory->createResolvedRecordFromDatabaseRow('tt_content', $contentRecord, null, $pageLayoutContext->getRecordIdentityMap()); $columnItem = GeneralUtility::makeInstance(GridColumnItem::class, $pageLayoutContext, $gridColumn, $contentRecord); return $columnItem->getPreview(); } return $content; } private function getBackendUser(): BackendUserAuthentication { return $GLOBALS['BE_USER']; } /** * Create a manipulated request with custom NormalizedParams to override the return URL. * This allows customizing the return URL used by PageLayoutContext->getReturnUrl() * without modifying the original request or the PageLayoutContext logic. */ private function getManipulatedRequestToFormEditor(ServerRequestInterface $request, array $contentRecord): ServerRequestInterface { $serverParams = $request->getServerParams(); $serverParams['REQUEST_URI'] = $this->buildCustomReturnUrl($request, $contentRecord); $customNormalizedParams = NormalizedParams::createFromServerParams($serverParams); return $request->withAttribute('normalizedParams', $customNormalizedParams); } /** * Build the custom return URL for the form editor. * Generates the URL to FormEditor->index action with the formPersistenceIdentifier parameter. */ private function buildCustomReturnUrl(ServerRequestInterface $request, array $contentRecord): string { $formPersistenceIdentifier = $this->arguments['formPersistenceIdentifier'] ?? ''; if (empty($formPersistenceIdentifier)) { return $request->getAttribute('normalizedParams')->getRequestUri(); } $uri = $this->uriBuilder->buildUriFromRoute( 'form_editor', ['formPersistenceIdentifier' => $formPersistenceIdentifier] ); return (string)$uri; } }