[英]Create an and validate Parent/Child Objects with Typo3 Extbase Fluid
我想在一個流體視圖窗體中創建一個父對象,並在StorageObject中創建幾個子對象(1:n關系)。 FormData將被傳輸到數據庫,如果發生錯誤,則新屬性映射器的驗證器將其返回。 但是僅在父對象的表單字段中,才會顯示“ f3-form-error”類。 但是在不一致的子對象上什么也不會發生。
(在Typo3 6.2.5中工作)
如下面的簡短示例所示,ChildObjects Authors的Propertymapping沒有獲得給定的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)
經過幾天的努力,我終於找到了一個骯臟的解決方案。 我編寫了自己的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++;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.