110 parent::initializeArguments();
111 $this->registerArgument(
'action',
'string',
'Target action');
112 $this->registerArgument(
'arguments',
'array',
'Arguments',
false, []);
113 $this->registerArgument(
'controller',
'string',
'Target controller');
114 $this->registerArgument(
'extensionName',
'string',
'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used');
115 $this->registerArgument(
'pluginName',
'string',
'Target plugin. If empty, the current plugin name is used');
116 $this->registerArgument(
'pageUid',
'int',
'Target page uid');
117 $this->registerArgument(
'object',
'mixed',
'Object to use for the form. Use in conjunction with the "property" attribute on the sub tags');
118 $this->registerArgument(
'pageType',
'int',
'Target page type',
false, 0);
119 $this->registerArgument(
'noCache',
'bool',
'set this to disable caching for the target page. You should not need this.',
false,
false);
120 $this->registerArgument(
'noCacheHash',
'bool',
'set this to suppress the cHash query parameter created by TypoLink. You should not need this.',
false,
false);
121 $this->registerArgument(
'section',
'string',
'The anchor to be added to the action URI (only active if $actionUri is not set)',
false,
'');
122 $this->registerArgument(
'format',
'string',
'The requested format (e.g. ".html") of the target page (only active if $actionUri is not set)',
false,
'');
123 $this->registerArgument(
'additionalParams',
'array',
'additional action URI query parameters that won\'t be prefixed like $arguments (overrule $arguments) (only active if $actionUri is not set)',
false, []);
124 $this->registerArgument(
'absolute',
'bool',
'If set, an absolute action URI is rendered (only active if $actionUri is not set)',
false,
false);
125 $this->registerArgument(
'addQueryString',
'bool',
'If set, the current query parameters will be kept in the action URI (only active if $actionUri is not set)',
false,
false);
126 $this->registerArgument(
'argumentsToBeExcludedFromQueryString',
'array',
'arguments to be removed from the action URI. Only active if $addQueryString = TRUE and $actionUri is not set',
false, []);
127 $this->registerArgument(
'addQueryStringMethod',
'string',
'Method to use when keeping query parameters (GET or POST, only active if $actionUri is not set',
false,
'GET');
128 $this->registerArgument(
'fieldNamePrefix',
'string',
'Prefix that will be added to all field names within this form. If not set the prefix will be tx_yourExtension_plugin');
129 $this->registerArgument(
'actionUri',
'string',
'can be used to overwrite the "action" attribute of the form tag');
130 $this->registerArgument(
'objectName',
'string',
'name of the object that is bound to this form. If this argument is not specified, the name attribute of this form is used to determine the FormObjectName');
131 $this->registerArgument(
'hiddenFieldClassName',
'string',
'hiddenFieldClassName');
132 $this->registerTagAttribute(
'enctype',
'string',
'MIME type with which the form is submitted');
133 $this->registerTagAttribute(
'method',
'string',
'Transfer type (GET or POST)');
134 $this->registerTagAttribute(
'name',
'string',
'Name of form');
135 $this->registerTagAttribute(
'onreset',
'string',
'JavaScript: On reset of the form');
136 $this->registerTagAttribute(
'onsubmit',
'string',
'JavaScript: On submit of the form');
137 $this->registerTagAttribute(
'target',
'string',
'Target attribute of the form');
138 $this->registerTagAttribute(
'novalidate',
'bool',
'Indicate that the form is not to be validated on submit.');
139 $this->registerUniversalTagAttributes();
150 if (isset($this->arguments[
'method']) && strtolower($this->arguments[
'method']) ===
'get') {
151 $this->tag->addAttribute(
'method',
'get');
153 $this->tag->addAttribute(
'method',
'post');
156 if (isset($this->arguments[
'novalidate']) && $this->arguments[
'novalidate'] ===
true) {
157 $this->tag->addAttribute(
'novalidate',
'novalidate');
164 $formContent = $this->renderChildren();
166 if (isset($this->arguments[
'hiddenFieldClassName']) && $this->arguments[
'hiddenFieldClassName'] !==
null) {
167 $content = LF .
'<div class="' . htmlspecialchars($this->arguments[
'hiddenFieldClassName']) .
'">';
169 $content = LF .
'<div>';
179 $content .= LF .
'</div>' . LF;
180 $content .= $formContent;
181 $this->tag->setContent($content);
187 return $this->tag->render();
195 if ($this->hasArgument(
'actionUri')) {
196 $formActionUri = $this->arguments[
'actionUri'];
198 $pageUid = (isset($this->arguments[
'pageUid']) && (int)$this->arguments[
'pageUid'] > 0) ? (int)$this->arguments[
'pageUid'] :
null;
199 $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
200 $formActionUri = $uriBuilder
202 ->setTargetPageUid($pageUid)
203 ->setTargetPageType($this->arguments[
'pageType'] ?? 0)
204 ->setNoCache($this->arguments[
'noCache'] ??
false)
205 ->setUseCacheHash(isset($this->arguments[
'noCacheHash']) ? !$this->arguments[
'noCacheHash'] :
true)
206 ->setSection($this->arguments[
'section'] ??
'')
207 ->setCreateAbsoluteUri($this->arguments[
'absolute'] ??
false)
208 ->setArguments(isset($this->arguments[
'additionalParams']) ? (array)$this->arguments[
'additionalParams'] : [])
209 ->setAddQueryString($this->arguments[
'addQueryString'] ??
false)
210 ->setAddQueryStringMethod($this->arguments[
'addQueryStringMethod'] ??
null)
211 ->setArgumentsToBeExcludedFromQueryString(isset($this->arguments[
'argumentsToBeExcludedFromQueryString']) ? (array)$this->arguments[
'argumentsToBeExcludedFromQueryString'] : [])
212 ->setFormat($this->arguments[
'format'] ??
'')
214 $this->arguments[
'action'] ??
null,
215 $this->arguments[
'arguments'] ?? [],
216 $this->arguments[
'controller'] ??
null,
217 $this->arguments[
'extensionName'] ??
null,
218 $this->arguments[
'pluginName'] ??
null
220 $this->formActionUriArguments = $uriBuilder->getArguments();
222 $this->tag->addAttribute(
'action', $formActionUri);
233 $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
234 if ($viewHelperVariableContainer->exists(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'additionalIdentityProperties')) {
235 $additionalIdentityProperties = $viewHelperVariableContainer->get(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'additionalIdentityProperties');
237 foreach ($additionalIdentityProperties as $identity) {
254 $request = $this->renderingContext->getControllerContext()->getRequest();
255 $extensionName = $request->getControllerExtensionName();
256 $vendorName = $request->getControllerVendorName();
257 $controllerName = $request->getControllerName();
258 $actionName = $request->getControllerActionName();
260 '@extension' => $extensionName,
261 '@controller' => $controllerName,
262 '@action' => $actionName,
266 $result .=
'<input type="hidden" name="' . htmlspecialchars($this->
prefixFieldName(
'__referrer[@extension]')) .
'" value="' . htmlspecialchars($extensionName) .
'" />' . LF;
267 if ($vendorName !==
null) {
268 $result .=
'<input type="hidden" name="' . $this->
prefixFieldName(
'__referrer[@vendor]') .
'" value="' . $vendorName .
'" />' . LF;
269 $actionRequest[
'@vendor'] = $vendorName;
271 $result .=
'<input type="hidden" name="' . htmlspecialchars($this->
prefixFieldName(
'__referrer[@controller]')) .
'" value="' . htmlspecialchars($controllerName) .
'" />' . LF;
272 $result .=
'<input type="hidden" name="' . htmlspecialchars($this->
prefixFieldName(
'__referrer[@action]')) .
'" value="' . htmlspecialchars($actionName) .
'" />' . LF;
273 $result .=
'<input type="hidden" name="' . htmlspecialchars($this->
prefixFieldName(
'__referrer[arguments]')) .
'" value="' . htmlspecialchars($this->hashService->appendHmac(base64_encode(serialize($request->getArguments())))) .
'" />' . LF;
274 $result .=
'<input type="hidden" name="' . htmlspecialchars($this->
prefixFieldName(
'__referrer[@request]')) .
'" value="' . htmlspecialchars($this->hashService->appendHmac(serialize($actionRequest))) .
'" />' . LF;
285 if ($formObjectName !==
null) {
286 $this->renderingContext->getViewHelperVariableContainer()->add(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'formObjectName', $formObjectName);
296 if ($formObjectName !==
null) {
297 $this->renderingContext->getViewHelperVariableContainer()->remove(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'formObjectName');
310 $formObjectName =
null;
311 if ($this->hasArgument(
'objectName')) {
312 $formObjectName = $this->arguments[
'objectName'];
313 } elseif ($this->hasArgument(
'name')) {
314 $formObjectName = $this->arguments[
'name'];
316 return $formObjectName;
324 if ($this->hasArgument(
'object')) {
325 $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
326 $viewHelperVariableContainer->add(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'formObject', $this->arguments[
'object']);
327 $viewHelperVariableContainer->add(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'additionalIdentityProperties', []);
336 if ($this->hasArgument(
'object')) {
337 $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
338 $viewHelperVariableContainer->remove(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'formObject');
339 $viewHelperVariableContainer->remove(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'additionalIdentityProperties');
349 $this->renderingContext->getViewHelperVariableContainer()->add(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'fieldNamePrefix', $fieldNamePrefix);
359 if ($this->hasArgument(
'fieldNamePrefix')) {
360 return $this->arguments[
'fieldNamePrefix'];
370 $this->renderingContext->getViewHelperVariableContainer()->remove(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'fieldNamePrefix');
378 $this->renderingContext->getViewHelperVariableContainer()->add(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'formFieldNames', []);
386 $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
387 $viewHelperVariableContainer->remove(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'formFieldNames');
388 if ($viewHelperVariableContainer->exists(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'renderedHiddenFields')) {
389 $viewHelperVariableContainer->remove(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'renderedHiddenFields');
400 $formFieldNames = $this->viewHelperVariableContainer->get(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'formFieldNames');
402 $requestHash = $this->requestHashService->generateRequestHash($formFieldNames, $this->
getFieldNamePrefix());
403 return '<input type="hidden" name="' . $this->
prefixFieldName(
'__hmac') .
'" value="' . htmlspecialchars($requestHash) .
'" />';
415 if (count($arguments)) {
416 foreach ($arguments as $argumentName => $argumentValue) {
417 if (is_array($argumentValue)) {
418 $prefix = $level == 0 ? $argumentName : $currentPrefix .
'[' . $argumentName .
']';
421 $results[] = $level == 0 ? $argumentName : $currentPrefix .
'[' . $argumentName .
']';
434 $request = $this->renderingContext->getControllerContext()->getRequest();
435 if ($this->hasArgument(
'extensionName')) {
436 $extensionName = $this->arguments[
'extensionName'];
438 $extensionName = $request->getControllerExtensionName();
440 if ($this->hasArgument(
'pluginName')) {
441 $pluginName = $this->arguments[
'pluginName'];
443 $pluginName = $request->getPluginName();
445 if ($extensionName !==
null && $pluginName !=
null) {
446 return $this->extensionService->getPluginNamespace($extensionName, $pluginName);
456 $viewHelperVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
457 if ($viewHelperVariableContainer->exists(\
TYPO3\CMS\Fluid\ViewHelpers\Form\CheckboxViewHelper::class,
'checkboxFieldNames')) {
458 $viewHelperVariableContainer->remove(\
TYPO3\CMS\Fluid\ViewHelpers\Form\CheckboxViewHelper::class,
'checkboxFieldNames');
469 $formFieldNames = $this->renderingContext->getViewHelperVariableContainer()->get(\
TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
'formFieldNames');
470 $requestHash = $this->mvcPropertyMappingConfigurationService->generateTrustedPropertiesToken($formFieldNames, $this->
getFieldNamePrefix());
471 return '<input type="hidden" name="' . htmlspecialchars($this->
prefixFieldName(
'__trustedProperties')) .
'" value="' . htmlspecialchars($requestHash) .
'" />';