‪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\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25 
49 class ‪EditRecordViewHelper extends AbstractViewHelper
50 {
51  use CompileWithRenderStatic;
52 
53  public function ‪initializeArguments()
54  {
55  $this->registerArgument('uid', 'int', 'uid of record to be edited, 0 for creation', true);
56  $this->registerArgument('table', 'string', 'target database table', true);
57  $this->registerArgument('fields', 'string', 'Edit only these fields (comma separated list)', false);
58  $this->registerArgument('returnUrl', 'string', 'return to this URL after closing the edit dialog', false, '');
59  }
60 
69  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
70  {
71  if ($arguments['uid'] < 1) {
72  throw new \InvalidArgumentException('Uid must be a positive integer, ' . $arguments['uid'] . ' given.', 1526128259);
73  }
74  if (empty($arguments['returnUrl'])) {
75  $arguments['returnUrl'] = GeneralUtility::getIndpEnv('REQUEST_URI');
76  }
77 
78  $params = [
79  'edit' => [$arguments['table'] => [$arguments['uid'] => 'edit']],
80  'returnUrl' => $arguments['returnUrl']
81  ];
82  if ($arguments['fields'] ?? false) {
83  $params['columnsOnly'] = $arguments['fields'];
84  }
85  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
86  return (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
87  }
88 }
‪TYPO3\CMS\Backend\ViewHelpers\Uri\EditRecordViewHelper
Definition: EditRecordViewHelper.php:50
‪TYPO3\CMS\Backend\ViewHelpers\Uri\EditRecordViewHelper\initializeArguments
‪initializeArguments()
Definition: EditRecordViewHelper.php:52
‪TYPO3\CMS\Backend\ViewHelpers\Uri\EditRecordViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: EditRecordViewHelper.php:68
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\ViewHelpers\Uri
Definition: EditRecordViewHelper.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46