Typo3 数组的Extbase属性映射
我想使用属性映射器在流体表单中使用数组对象。如果用户单击“添加产品”链接,则会动态添加产品: 隐藏字段解析为:Typo3 数组的Extbase属性映射,typo3,extbase,typo3-7.6.x,Typo3,Extbase,Typo3 7.6.x,我想使用属性映射器在流体表单中使用数组对象。如果用户单击“添加产品”链接,则会动态添加产品: 隐藏字段解析为:(静态值8只是为了简化示例) 我还尝试了key=“key”而不是迭代器,使用空括号orderProduct[],使用name而不是property,但没有结果 这是(简化的)调试输出: newOrder (MyVendor\MyShop\Domain\Model\ShopOrder) => orderProduct (TYPO3\CMS\Extbase\Persistence
(静态值8只是为了简化示例)
我还尝试了key=“key”
而不是迭代器,使用空括号orderProduct[]
,使用name而不是property,但没有结果
这是(简化的)调试输出:
newOrder (MyVendor\MyShop\Domain\Model\ShopOrder)
=> orderProduct (TYPO3\CMS\Extbase\Persistence\ObjectStorage)
3222112 => MyVendor\MyShop\Domain\Model\OrderProduct
product => MyVendor\MyShop\Domain\Model\Product
uid => 8
title => 'Product1'
这是型号代码:
- 订单
- 订单产品
public function initializePropertyAction()
{
/** @var \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration */
$propertyMappingConfiguration = $this->arguments['newOrder']->getPropertyMappingConfiguration();
$propertyMappingConfiguration->allowAllProperties();
$propertyMappingConfiguration->setTypeConverterOption('TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
TRUE);
$propertyMappingConfiguration->forProperty('orderProduct')->allowAllProperties();
$propertyMappingConfiguration->forProperty('orderProduct')->setTypeConverterOption(
'TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
TRUE
);
//workaround from https://forge.typo3.org/issues/61628
for ($i = 0; $i < 99; $i++) {
$propertyMappingConfiguration->forProperty('orderProduct.' . $i)->allowAllProperties();
$propertyMappingConfiguration->forProperty('orderProduct.' . $i . '.*')->allowAllProperties();
$propertyMappingConfiguration->forProperty('orderProduct.' . $i)->setTypeConverterOption(
'TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
TRUE
);
}
}
public函数initializePropertyAction()
{
/**@var\TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration$PropertyMappingConfiguration*/
$propertyMappingConfiguration=$this->arguments['newOrder']->getPropertyMappingConfiguration();
$propertyMappingConfiguration->AllowlProperties();
$propertyMappingConfiguration->setTypeConverterOption('Type3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::允许配置\u创建\u,
正确的);
$propertyMappingConfiguration->forProperty('orderProduct')->AllowlProperties();
$propertyMappingConfiguration->forProperty('orderProduct')->setTypeConverterOption(
'TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::允许配置\u创建\u,
真的
);
//从https://forge.typo3.org/issues/61628
对于($i=0;$i<99;$i++){
$propertyMappingConfiguration->forProperty('orderProduct..$i)->AllowlProperties();
$propertyMappingConfiguration->forProperty('orderProduct.'.$i.'.*')->AllowAllowlProperties();
$propertyMappingConfiguration->forProperty('orderProduct..$i)->setTypeConverterOption(
'TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::允许配置\u创建\u,
真的
);
}
}
我是这样解决的,对于一个有两个字段的动态答案数的问题,每个字段:
$propertyMappingConfiguration = $this->arguments->getArgument('question')->getPropertyMappingConfiguration();
$propertyMappingConfiguration->skipProperties('category');
$propertyMappingConfiguration->allowProperties('answers');
$propertyMappingConfiguration->forProperty('answers.*')->allowProperties('answerField1', 'answerField2');
$propertyMappingConfiguration->allowCreationForSubProperty('answers.*');
$propertyMappingConfiguration->allowModificationForSubProperty('answers.*');
“allowCreationForSubProperty”在7.6中不可用-但我认为我使用的setTypeConverterOption也在做同样的事情吗?
tx\u myshop\u pi1[newOrder][orderProduct][0]
来自于class Product是否正确?因为这是例外所说的。我假设您的模型产品不包含名为Product的属性。tx_myshop_pi1[newOrder][orderProduct][0]来自类ObjectStorage,tx_myshop_pi1[newOrder][orderProduct][0][Product]来自类Product。我为模型代码添加了pastebin链接-您可以检查这是否是错误源。如果需要某种类型的类型转换,我可以使用一些帮助来完成此操作。已解决-错误在模型中,而不是在PropertyMappingtx_myshop_pi1[newOrder][orderProduct]来自ObjectStorage类。[0]已是存储中的第一项。但是是的,你已经修好了!
public function initializePropertyAction()
{
/** @var \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration */
$propertyMappingConfiguration = $this->arguments['newOrder']->getPropertyMappingConfiguration();
$propertyMappingConfiguration->allowAllProperties();
$propertyMappingConfiguration->setTypeConverterOption('TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
TRUE);
$propertyMappingConfiguration->forProperty('orderProduct')->allowAllProperties();
$propertyMappingConfiguration->forProperty('orderProduct')->setTypeConverterOption(
'TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
TRUE
);
//workaround from https://forge.typo3.org/issues/61628
for ($i = 0; $i < 99; $i++) {
$propertyMappingConfiguration->forProperty('orderProduct.' . $i)->allowAllProperties();
$propertyMappingConfiguration->forProperty('orderProduct.' . $i . '.*')->allowAllProperties();
$propertyMappingConfiguration->forProperty('orderProduct.' . $i)->setTypeConverterOption(
'TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter',
PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
TRUE
);
}
}
$propertyMappingConfiguration = $this->arguments->getArgument('question')->getPropertyMappingConfiguration();
$propertyMappingConfiguration->skipProperties('category');
$propertyMappingConfiguration->allowProperties('answers');
$propertyMappingConfiguration->forProperty('answers.*')->allowProperties('answerField1', 'answerField2');
$propertyMappingConfiguration->allowCreationForSubProperty('answers.*');
$propertyMappingConfiguration->allowModificationForSubProperty('answers.*');