【发布时间】:2019-11-24 20:39:52
【问题描述】:
我使用 TYPO3 系统扩展“表单”并希望使用 GET 参数预填充输入字段。
这个TYPO3 8.7. Form prefill input field 正在工作,但只有 no_cache=1。是否有另一种不停用整个缓存的解决方案?
谢谢 大卫
【问题讨论】:
我使用 TYPO3 系统扩展“表单”并希望使用 GET 参数预填充输入字段。
这个TYPO3 8.7. Form prefill input field 正在工作,但只有 no_cache=1。是否有另一种不停用整个缓存的解决方案?
谢谢 大卫
【问题讨论】:
是的,您可以,但您需要创建 HOOK。
这在documentation中有描述
例如,HOOK
/**
* @param \TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable
* @return void
*/
public function initializeFormElement(\TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable)
{
if ($renderable->getUniqueIdentifier() === 'contactForm-text-1') {
$renderable->setDefaultValue('foo');
}
}
还有连接钩子
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'][<useATimestampAsKeyPlease>]
= \VENDOR\YourNamespace\YourClass::class;
请阅读“表单框架”的文档。
我做到了,得到了我需要的结果。
【讨论】:
您可以禁用表单页面内容列的缓存,例如:
lib.content = COA
lib.content{
10 < styles.content.get
}
[page["uid"] == 512]
lib.content = COA_INT
[global]
【讨论】:
config.no_cache = 1禁用单个页面的缓存不是更容易吗?
感谢 TYPO3UA 的回答。但是你应该使用钩子'afterBuildingFinished',因为'initializeFormElement'钩子是在表单定义的属性设置在表单元素中之前执行的。因此,表单定义中的默认值(即使它是一个空字符串)将覆盖在 initializeFormElement' 挂钩中设置的值。 见:https://forge.typo3.org/issues/82615
所以这适用于设置表单元素的默认值:
/**
* @param \TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable
* @return void
*/
public function afterBuildingFinished(\TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface $renderable)
{
if (method_exists($renderable, 'getUniqueIdentifier') && $renderable->getUniqueIdentifier() === 'contactForm-text-1') {
$renderable->setDefaultValue('Value');
}
}
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterBuildingFinished'][<useATimestampAsKeyPlease>]
= \VENDOR\YourNamespace\YourClass::class;
【讨论】: