Skip to content

Commit

Permalink
[Admin] Minor improvements for promotion's form component
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Apr 18, 2024
1 parent e803c6f commit b004e01
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
);
}
Expand All @@ -85,4 +83,10 @@ private function provideItemType(string $name): string

return '';
}

/** @param array<array-key, array<string, mixed>> $data */
private function resolveItemIndex(array $data): int
{
return [] !== $data ? max(array_keys($data)) + 1 : 0;
}
}

0 comments on commit b004e01

Please sign in to comment.