`. * * ``` * * ``` * * @see https://docs.typo3.org/permalink/t3viewhelper:typo3-backend-uri-editrecord * @see https://docs.typo3.org/permalink/t3viewhelper:typo3-backend-uri-newrecord */ final class EditRecordViewHelper extends AbstractViewHelper { public function __construct( private readonly UriBuilder $uriBuilder ) {} public function initializeArguments(): void { $this->registerArgument('uid', 'int', 'uid of record to be edited, 0 for creation', true); $this->registerArgument('table', 'string', 'target database table', true); $this->registerArgument('fields', 'string', 'Edit only these fields (comma separated list)'); $this->registerArgument('module', 'string', 'Set module identifier for context - marking as acitve when editing the record', false, ''); $this->registerArgument('returnUrl', 'string', 'return to this URL after closing the edit dialog', false, ''); } /** * @throws InvalidArgumentValueException * @throws RouteNotFoundException */ public function render(): string { if ($this->arguments['uid'] < 1) { throw new InvalidArgumentValueException('Uid must be a positive integer, ' . $this->arguments['uid'] . ' given.', 1526128259); } $request = $this->renderingContext->hasAttribute(ServerRequestInterface::class) ? $this->renderingContext->getAttribute(ServerRequestInterface::class) : null; if (empty($this->arguments['returnUrl']) && $request !== null) { $this->arguments['returnUrl'] = $request->getAttribute('normalizedParams')->getRequestUri(); } $params = [ 'edit' => [$this->arguments['table'] => [$this->arguments['uid'] => 'edit']], 'module' => ($this->arguments['module'] ?? '') ?: ($request?->getAttribute('module')?->getIdentifier() ?? ''), 'returnUrl' => $this->arguments['returnUrl'], ]; if ($this->arguments['fields'] ?? false) { $params['columnsOnly'] = [ $this->arguments['table'] => GeneralUtility::trimExplode(',', $this->arguments['fields'], true), ]; } return (string)$this->uriBuilder->buildUriFromRoute('record_edit', $params); } }