entityManager = $entityManager; } public function setNewsletter(UserInterface $user, NewsletterInterface $newsletter, bool $subscribeNewsletter): void { if ($subscribeNewsletter) { $user->addNewsletter($newsletter); } else { $user->removeNewsletter($newsletter); } $this->entityManager->persist($user); $this->entityManager->flush(); } }