From 315cc30a1a7dcb6b40ab6a9ee2592aa4611332a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 6 Apr 2020 11:52:42 +0200 Subject: [PATCH] Fix error with reindexed collectionType when multiple parts dont have IDs yet. --- src/Form/CollectionTypeExtension.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Form/CollectionTypeExtension.php b/src/Form/CollectionTypeExtension.php index 53a06b56..01bc6a89 100644 --- a/src/Form/CollectionTypeExtension.php +++ b/src/Form/CollectionTypeExtension.php @@ -84,7 +84,9 @@ class CollectionTypeExtension extends AbstractTypeExtension $error_mapping = []; foreach ($data->toArray() as $key => $item) { - $index = $options['reindex_prefix'] . $this->propertyAccess->getValue($item, $options['reindex_path']); + $id = $this->propertyAccess->getValue($item, $options['reindex_path']); + //If element has an ID then use it. otherwise use default key + $index = $id === null ? $key : $options['reindex_prefix'] . $id; $error_mapping['[' . $key . ']'] = $index; $reindexed_data->set($index, $item); }