`. * * Examples * ======== * * Link to the record-edit action passed to FormEngine:: * * * * Output:: * * * Edit record * * * Link to edit page uid=3 and then return back to the BE module "web_MyextensionList":: * * * * Link to edit only the fields title and subtitle of page uid=42 and return to foo/bar:: * * * Edit record * * * Output:: * * * Edit record * * * @see https://docs.typo3.org/permalink/t3viewhelper:typo3-backend-link-editrecord */ final class EditRecordViewHelper extends AbstractTagBasedViewHelper { /** * @var string */ protected $tagName = 'a'; public function __construct( private readonly UriBuilder $uriBuilder ) { parent::__construct(); } public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('uid', 'int', 'uid of record to be edited', 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 active when editing the record', false, ''); $this->registerArgument('returnUrl', 'string', 'return to this URL after closing the edit dialog', false, ''); } /** * @throws \InvalidArgumentException * @throws RouteNotFoundException */ public function render(): string { if ($this->arguments['uid'] < 1) { throw new InvalidArgumentValueException('Uid must be a positive integer, ' . $this->arguments['uid'] . ' given.', 1526127158); } $request = $this->renderingContext->hasAttribute(ServerRequestInterface::class) ? $this->renderingContext->getAttribute(ServerRequestInterface::class) : null; if (empty($this->arguments['returnUrl']) && $request !== null) { // @todo: We may want to deprecate fetching returnUrl from request $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), ]; } $uri = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $params); $this->tag->addAttribute('href', $uri); $this->tag->setContent((string)$this->renderChildren()); $this->tag->forceClosingTag(true); return $this->tag->render(); } }