diff --git a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php index 812c7e0da9b..3facda289a0 100644 --- a/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/TwigComponent/Promotion/FormComponent.php @@ -59,11 +59,9 @@ public function addCollectionItem(PropertyAccessorInterface $propertyAccessor, # $data = []; } - $index = [] !== $data ? max(array_keys($data)) + 1 : 0; - $propertyAccessor->setValue( $this->formValues, - $propertyPath."[$index]", + sprintf('%s[%d]', $propertyPath, $this->resolveItemIndex($data)), ['type' => $this->provideItemType($name)], ); } @@ -85,4 +83,10 @@ private function provideItemType(string $name): string return ''; } + + /** @param array> $data */ + private function resolveItemIndex(array $data): int + { + return [] !== $data ? max(array_keys($data)) + 1 : 0; + } }