fix : use custom EnvironmentCreateProcessor to properly add environments

API Platform's default sub-resource POST was replacing instead of adding.
Custom processor with read:false + Link + manual persist fixes this.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-06 16:49:44 +02:00
parent c7e32c74b6
commit a3cd1f6b74
2 changed files with 47 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Repository\EnvironmentRepository;
use App\State\EnvironmentCreateProcessor;
use App\State\MaintenanceToggleProcessor;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@@ -23,7 +24,9 @@ use Symfony\Component\Serializer\Attribute\Groups;
uriVariables: [
'slug' => new Link(toProperty: 'application', fromClass: Application::class, identifiers: ['slug']),
],
read: false,
security: "is_granted('ROLE_ADMIN')",
processor: EnvironmentCreateProcessor::class,
),
new Patch(
security: "is_granted('ROLE_ADMIN')",