数组的extbase属性映射



我想使用属性映射器在流体表单中使用数组对象。如果用户单击" add_product"链接:

<f:form action="property" name="newOrder" object="{newOrder}">
    <f:for each="{newOrder.orderProduct}" as="orderProduct" iteration="iterator">
        <f:form.hidden property="orderProduct.{iterator.index}.product" value="8" />
        <h3>OrderProduct: {orderProduct.product.title}</h3>
    </f:for>
    <f:form.hidden name="add_product" value="1" />
    <input type="submit" value="submit" />
</f:form>

我提交后得到的是这个例外。

Uncaught TYPO3 Exception #1297759968: 
Exception while property mapping at property path "orderProduct.0":
Property "product" was not found in target object of type "MyVendorMyShopDomainModelProduct". 

隐藏的字段解析为: <input name="tx_myshop_pi1[newOrder][orderProduct][0][product]" value="8" type="hidden">(8的静态值只是为了简化示例(

我还尝试使用 key="key"而不是迭代器,空括号orderProduct[],使用名称而不是属性没有结果。

这是(简化的(调试输出:

newOrder (MyVendorMyShopDomainModelShopOrder)
   => orderProduct (TYPO3CMSExtbasePersistenceObjectStorage)
      3222112 => MyVendorMyShopDomainModelOrderProduct
              product => MyVendorMyShopDomainModelProduct
                     uid => 8
                     title => 'Product1'  

这是模型代码:

  • 购物者https://pastebin.com/yn7x37ei
  • OrderProduct https://pastebin.com/zfyztlaq

对于属性映射器,我尝试了很多配置而没有成功。我认为这应该有效,但行不通:

public function initializePropertyAction()
{
    /** @var TYPO3CMSExtbasePropertyPropertyMappingConfiguration $propertyMappingConfiguration */
    $propertyMappingConfiguration = $this->arguments['newOrder']->getPropertyMappingConfiguration();
    $propertyMappingConfiguration->allowAllProperties();
    $propertyMappingConfiguration->setTypeConverterOption('TYPO3CMSExtbasePropertyTypeConverterPersistentObjectConverter',
        PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
        TRUE);
    $propertyMappingConfiguration->forProperty('orderProduct')->allowAllProperties();
    $propertyMappingConfiguration->forProperty('orderProduct')->setTypeConverterOption(
        'TYPO3CMSExtbasePropertyTypeConverterPersistentObjectConverter',
        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(
            'TYPO3CMSExtbasePropertyTypeConverterPersistentObjectConverter',
            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.*');

最新更新