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