您的问题是 viewhelper f:form 中打开的@todo
* @todo filter out referrer information that is equal to the target (e.g. same packageKey)
*/
protected function renderHiddenReferrerFields()
...
我的复制和粘贴解决方法是扩展 viewhelper f:form。我在我的扩展中定义了一个子类。
<?php
namespace Porth\Positioner\ViewHelpers;
class FormViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper {
/**
* Renders hidden form fields for referrer information about
* the current controller and action.
*
* Renders hidden form field for secured referrer information about the current controller and action.
*
* This method is called twice, to deal with subclasses of this class in a most compatible way
*
* @param string|null $action
* @param string|null $controller
* @param string|null $vendor
* @param string|null $extension
*
* @return string Hidden field with secured referrer information
* @todo filter out referrer information that is equal to the target (e.g. same packageKey)
*/
protected function renderHiddenReferrerFields($action =null, $controller = null, $vendor = null, $extension = null )
{
$request = $this->controllerContext->getRequest();
$extensionName = ((is_null($extension))? $request->getControllerExtensionName() : $extension);
$vendorName = ((is_null($vendor))? $request->getControllerVendorName() : $vendor);
$controllerName = ((is_null($controller)) ? $request->getControllerName() : $controller);
$actionName = ((is_null($action))? $request->getControllerActionName() : $action);
$result = LF;
$result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@extension]') . '" value="' . $extensionName . '" />' . LF;
if ($vendorName !== null) {
$result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@vendor]') . '" value="' . $vendorName . '" />' . LF;
}
$result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@controller]') . '" value="' . $controllerName . '" />' . LF;
$result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@action]') . '" value="' . $actionName . '" />' . LF;
$result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[arguments]') . '" value="' . htmlspecialchars($this->hashService->appendHmac(base64_encode(serialize($request->getArguments())))) . '" />' . LF;
$result .= $this->renderHiddenSecuredReferrerField($actionName, $controllerName, $vendorName, $extensionName);
return $result;
}
/**
* Renders hidden form field for secured referrer information about the current controller and action.
*
* This method is called twice, to deal with subclasses of this class in a most compatible way
*
* @param string|null $action
* @param string|null $controller
* @param string|null $vendor
* @param string|null $extension
*
* @return string Hidden field with secured referrer information
*/
protected function renderHiddenSecuredReferrerField($action = null, $controller = null, $vendor = null, $extension = null )
{
if ($this->securedReferrerFieldRendered) {
return '';
}
$request = $this->renderingContext->getControllerContext()->getRequest();
$extensionName = ((is_null($extension))? $request->getControllerExtensionName() : $extension);
$vendorName = ((is_null($vendor))? $request->getControllerVendorName() : $vendor);
$controllerName = ((is_null($controller)) ? $request->getControllerName() : $controller);
$actionName = ((is_null($action))? $request->getControllerActionName() : $action);
$actionRequest = [
'@extension' => $extensionName,
'@controller' => $controllerName,
'@action' => $actionName,
];
if ($vendorName !== null) {
$actionRequest['@vendor'] = $vendorName;
}
$result = '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@request]') . '" value="' . htmlspecialchars($this->hashService->appendHmac(serialize($actionRequest))) . '" />' . LF;
$this->securedReferrerFieldRendered = true;
return $result;
}
/**
* Render the form.
*
* @param string $action Target action
* @param array $arguments Arguments
* @param string $controller Target controller
* @param string $vendor Target vendor
* @param string $extensionName Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used
* @param string $pluginName Target plugin. If empty, the current plugin name is used
* @param int $pageUid Target page uid
* @param mixed $object Object to use for the form. Use in conjunction with the "property" attribute on the sub tags
* @param int $pageType Target page type
* @param bool $noCache set this to disable caching for the target page. You should not need this.
* @param bool $noCacheHash set this to suppress the cHash query parameter created by TypoLink. You should not need this.
* @param string $section The anchor to be added to the action URI (only active if $actionUri is not set)
* @param string $format The requested format (e.g. ".html") of the target page (only active if $actionUri is not set)
* @param array $additionalParams additional action URI query parameters that won't be prefixed like $arguments (overrule $arguments) (only active if $actionUri is not set)
* @param bool $absolute If set, an absolute action URI is rendered (only active if $actionUri is not set)
* @param bool $addQueryString If set, the current query parameters will be kept in the action URI (only active if $actionUri is not set)
* @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the action URI. Only active if $addQueryString = TRUE and $actionUri is not set
* @param string $fieldNamePrefix Prefix that will be added to all field names within this form. If not set the prefix will be tx_yourExtension_plugin
* @param string $actionUri can be used to overwrite the "action" attribute of the form tag
* @param string $objectName 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
* @param string $hiddenFieldClassName
* @return string rendered form
*/
public function render($action = null, array $arguments = array(), $controller = null, $vendor = null, $extensionName = null, $pluginName = null, $pageUid = null, $object = null, $pageType = 0, $noCache = false, $noCacheHash = false, $section = '', $format = '', array $additionalParams = array(), $absolute = false, $addQueryString = false, array $argumentsToBeExcludedFromQueryString = array(), $fieldNamePrefix = null, $actionUri = null, $objectName = null, $hiddenFieldClassName = null)
{
$this->setFormActionUri();
if (strtolower($this->arguments['method']) === 'get') {
$this->tag->addAttribute('method', 'get');
} else {
$this->tag->addAttribute('method', 'post');
}
$this->addFormObjectNameToViewHelperVariableContainer();
$this->addFormObjectToViewHelperVariableContainer();
$this->addFieldNamePrefixToViewHelperVariableContainer();
$this->addFormFieldNamesToViewHelperVariableContainer();
$formContent = $this->renderChildren();
if ($this->arguments['hiddenFieldClassName'] !== null) {
$content = LF . '<div class="' . htmlspecialchars($this->arguments['hiddenFieldClassName']) . '">';
} else {
$content = LF . '<div>';
}
$content .= $this->renderHiddenIdentityField($this->arguments['object'], $this->getFormObjectName());
$content .= $this->renderAdditionalIdentityFields();
$content .= $this->renderHiddenReferrerFields($action , $controller , $vendor , $extensionName );
// $content .= $this->renderHiddenSecuredReferrerField($action , $controller , $vendor , $extensionName );
// Render the trusted list of all properties after everything else has been rendered
$content .= $this->renderTrustedPropertiesField();
$content .= LF . '</div>' . LF;
$content .= $formContent;
$this->tag->setContent($content);
$this->removeFieldNamePrefixFromViewHelperVariableContainer();
$this->removeFormObjectFromViewHelperVariableContainer();
$this->removeFormObjectNameFromViewHelperVariableContainer();
$this->removeFormFieldNamesFromViewHelperVariableContainer();
$this->removeCheckboxFieldNamesFromViewHelperVariableContainer();
return $this->tag->render();
}
}