使用 Typo3 Extbase Fluid 创建并验证 Parent/Child 个对象
Create an and validate Parent/Child Objects with Typo3 Extbase Fluid
我想在 Fluid View Form 中创建一个父对象,在 StorageObject 中创建多个子对象(1:n 关系)。 FormData 将被传输到数据库,如果出现错误,NEW 属性 Mapper returns 的验证器将对其进行验证。但仅在父对象的表单字段中出现 "f3-form-error" class。但是在不一致的子对象上没有任何反应。
(使用 Typo3 6.2.5)
正如您在下面的一个简短示例中看到的,ChildObjects Authors 的 属性 映射没有获得给定的 UID。相反,Mapper 会提供一个自定义 ID。我认为这就是 ValidationResult 没有返回到输入框的原因。
请帮忙!
简短示例:
//控制器
public function initializeCreateAction() {
$this->arguments->getArgument('newSubmission')->getPropertyMappingConfiguration()->allowProperties('authors');
$this->arguments->getArgument('newSubmission')->getPropertyMappingConfiguration()->allowCreationForSubProperty('authors.*');
$this->arguments->getArgument('newSubmission')->getPropertyMappingConfiguration()->forProperty('authors.*')->allowProperties('firstname');
}
// 流体
<f:form.textfield property="type" /><br />
<f:for each="{authors}" as="author" key="uid" iteration="iterator">
<f:form.textfield property="authors.{uid}.firstname" placeholder="Enter your first given name" />
</f:for>
//调试
$result = $this->getControllerContext()->getRequest()->getOriginalRequestMappingResults();
//输出
array(19 items)
newSubmission.type => array(1 item)
0 => TYPO3\CMS\Extbase\Validation\Errorprototypeobject
message => 'The given subject was NULL.' (27 chars)
code => 1221560910 (integer)
arguments => array(empty)
title => '' (0 chars)
newSubmission.authors.000000006200d7b200007f3972b36107.email => array(1 item)
0 => TYPO3\CMS\Extbase\Validation\Errorprototypeobject
message => 'The given subject was not a valid email address.' (48 chars)
code => 1221559976 (integer)
arguments => array(empty)
title => '' (0 chars)
newSubmission.authors.000000006200d7b400007f3972b36107.email => array(1 item)
0 => TYPO3\CMS\Extbase\Validation\Errorprototypeobject
message => 'The given subject was not a valid email address.' (48 chars)
code => 1221559976 (integer)
arguments => array(empty)
title => '' (0 chars)
newSubmission.authors.000000006200d7b700007f3972b36107.email => array(1 item)
0 => TYPO3\CMS\Extbase\Validation\Errorprototypeobject
message => 'The given subject was not a valid email address.' (48 chars)
code => 1221559976 (integer)
arguments => array(empty)
title => '' (0 chars)
经过几天的努力,我终于找到了一个 DIRTY 解决方案。
我写了一个自己的 errorAction 并覆盖了值。必须有更好的解决方案!!!!这是我的代码:
protected function errorAction() {
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->arguments->getValidationResults()->forProperty('newSubmission.authors'));
$authorErrors = $this->arguments->getValidationResults()->forProperty('newSubmission.authors')->getSubResults();
$i = 1;
foreach ( $authorErrors as $uid => $author) {
foreach ( $author->getSubResults() as $property => $error) {
$this->arguments->getValidationResults()->forProperty('newSubmission.authors.'.$i.'.'.$property)->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', time()));
}
$i++;
}
}
我想在 Fluid View Form 中创建一个父对象,在 StorageObject 中创建多个子对象(1:n 关系)。 FormData 将被传输到数据库,如果出现错误,NEW 属性 Mapper returns 的验证器将对其进行验证。但仅在父对象的表单字段中出现 "f3-form-error" class。但是在不一致的子对象上没有任何反应。
(使用 Typo3 6.2.5)
正如您在下面的一个简短示例中看到的,ChildObjects Authors 的 属性 映射没有获得给定的 UID。相反,Mapper 会提供一个自定义 ID。我认为这就是 ValidationResult 没有返回到输入框的原因。
请帮忙!
简短示例:
//控制器
public function initializeCreateAction() {
$this->arguments->getArgument('newSubmission')->getPropertyMappingConfiguration()->allowProperties('authors');
$this->arguments->getArgument('newSubmission')->getPropertyMappingConfiguration()->allowCreationForSubProperty('authors.*');
$this->arguments->getArgument('newSubmission')->getPropertyMappingConfiguration()->forProperty('authors.*')->allowProperties('firstname');
}
// 流体
<f:form.textfield property="type" /><br />
<f:for each="{authors}" as="author" key="uid" iteration="iterator">
<f:form.textfield property="authors.{uid}.firstname" placeholder="Enter your first given name" />
</f:for>
//调试
$result = $this->getControllerContext()->getRequest()->getOriginalRequestMappingResults();
//输出
array(19 items)
newSubmission.type => array(1 item)
0 => TYPO3\CMS\Extbase\Validation\Errorprototypeobject
message => 'The given subject was NULL.' (27 chars)
code => 1221560910 (integer)
arguments => array(empty)
title => '' (0 chars)
newSubmission.authors.000000006200d7b200007f3972b36107.email => array(1 item)
0 => TYPO3\CMS\Extbase\Validation\Errorprototypeobject
message => 'The given subject was not a valid email address.' (48 chars)
code => 1221559976 (integer)
arguments => array(empty)
title => '' (0 chars)
newSubmission.authors.000000006200d7b400007f3972b36107.email => array(1 item)
0 => TYPO3\CMS\Extbase\Validation\Errorprototypeobject
message => 'The given subject was not a valid email address.' (48 chars)
code => 1221559976 (integer)
arguments => array(empty)
title => '' (0 chars)
newSubmission.authors.000000006200d7b700007f3972b36107.email => array(1 item)
0 => TYPO3\CMS\Extbase\Validation\Errorprototypeobject
message => 'The given subject was not a valid email address.' (48 chars)
code => 1221559976 (integer)
arguments => array(empty)
title => '' (0 chars)
经过几天的努力,我终于找到了一个 DIRTY 解决方案。 我写了一个自己的 errorAction 并覆盖了值。必须有更好的解决方案!!!!这是我的代码:
protected function errorAction() {
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->arguments->getValidationResults()->forProperty('newSubmission.authors'));
$authorErrors = $this->arguments->getValidationResults()->forProperty('newSubmission.authors')->getSubResults();
$i = 1;
foreach ( $authorErrors as $uid => $author) {
foreach ( $author->getSubResults() as $property => $error) {
$this->arguments->getValidationResults()->forProperty('newSubmission.authors.'.$i.'.'.$property)->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', time()));
}
$i++;
}
}