requireRole($this->security, 'ROLE_GESTIONNAIRE'); $composant = $this->composants->find($composantId); if (!$composant) { $this->mcpError('not_found', "Composant not found: {$composantId}"); } if (null !== $name) { $composant->setName($name); } if (null !== $reference) { $composant->setReference($reference); } if (null !== $description) { $composant->setDescription($description); } if (null !== $prix) { $composant->setPrix($prix); } if (null !== $modelTypeId) { if ('' === $modelTypeId) { $composant->setTypeComposant(null); } else { $modelType = $this->modelTypes->find($modelTypeId); if (!$modelType) { $this->mcpError('not_found', "ModelType not found: {$modelTypeId}"); } $composant->setTypeComposant($modelType); } } if (null !== $constructeurIds) { foreach ($composant->getConstructeurs()->toArray() as $existing) { $composant->removeConstructeur($existing); } foreach ($constructeurIds as $cId) { $c = $this->constructeurs->find($cId); if (!$c) { $this->mcpError('not_found', "Constructeur not found: {$cId}"); } $composant->addConstructeur($c); } } $this->em->flush(); return $this->jsonResponse(['id' => $composant->getId(), 'name' => $composant->getName()]); } }