У меня есть форма, и я добавляю этот элемент:
->add("usedTileLocations", UsedTilesFormType::class, [ ])
UsedTilesFormType =
$builder
->add("usedTileLocations", EntityType::class, [
"class" => TileLocations::class,
"multiple" => true,
"required" => false,
"choice_label" => "getLabel",
'query_builder' => function (EntityRepository $er) use ($currentCustomer) {
return $er->createQueryBuilder('tileLocation')
->where('tileLocation.customer = :customer')
->setParameter('customer', $currentCustomer);
},
])
;
$builder->get('usedTileLocations')
->addModelTransformer(new CallbackTransformer(
function ($savedTiles) {
return $savedTiles;
},
function ($selectedTiles) {
dump("incoming selected collection : ");
dump($selectedTiles);
$usedTiles = new ArrayCollection();
foreach( $selectedTiles as $aTile ) {
/** @var TileLocations $aTile */
$aUsedTile = new UsedTileLocations();
$aUsedTile->setTileColumn($aTile->getTileColumn());
$aUsedTile->setTileRow($aTile->getTileRow());
$aUsedTile->setCustomer($aTile->getCustomer());
$usedTiles->add($aUsedTile);
}
dump("outgoing selected collection : ");
dump($usedTiles);
return $usedTiles; // having same issue returning all selections here.
//return $usedTiles[0]; // Works but only saves the first selected entity.
}
))
;
Вывод дампов:
"incoming selected collection : "
ArrayCollection {#2132
-elements: array:2 [
0 => TileLocations {#2143 ▶}
1 => TileLocations {#2125 ▶}
]
}
"outgoing selected collection : "
ArrayCollection {#230
-elements: array:2 [
0 => UsedTileLocations {#2157 ▶}
1 => UsedTileLocations {#2162 ▶}
]
}
И этоприводит к ошибке:
Класс 'Doctrine \ Common \ Collections \ ArrayCollection' не найден в настроенных цепочках пространств имен App \ Entity, Vich \ UploaderBundle \ Entity, FOS \ UserBundle \ Model
Если я верну первый элемент в коллекции, он сохранится, но не займет всю коллекцию.
Что я здесь не так делаю?Большое спасибо, что нашли время, чтобы прочитать это.