‪TYPO3CMS  10.4
EditRecordViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
23 
60 class ‪EditRecordViewHelper extends AbstractTagBasedViewHelper
61 {
65  protected ‪$tagName = 'a';
66 
67  public function ‪initializeArguments()
68  {
69  parent::initializeArguments();
70  $this->registerUniversalTagAttributes();
71  $this->registerArgument('uid', 'int', 'uid of record to be edited', true);
72  $this->registerArgument('table', 'string', 'target database table', true);
73  $this->registerArgument('fields', 'string', 'Edit only these fields (comma separated list)', false);
74  $this->registerArgument('returnUrl', 'string', 'return to this URL after closing the edit dialog', false, '');
75  }
76 
81  public function ‪render(): string
82  {
83  if ($this->arguments['uid'] < 1) {
84  throw new \InvalidArgumentException('Uid must be a positive integer, ' . $this->arguments['uid'] . ' given.', 1526127158);
85  }
86  if (empty($this->arguments['returnUrl'])) {
87  $this->arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
88  }
89 
90  $params = [
91  'edit' => [$this->arguments['table'] => [$this->arguments['uid'] => 'edit']],
92  'returnUrl' => $this->arguments['returnUrl']
93  ];
94  if ($this->arguments['fields'] ?? false) {
95  $params['columnsOnly'] = $this->arguments['fields'];
96  }
97  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
98  $uri = (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
99  $this->tag->addAttribute('href', $uri);
100  $this->tag->setContent($this->renderChildren());
101  $this->tag->forceClosingTag(true);
102  return $this->tag->render();
103  }
104 }
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46