Ejemplo n.º 1
0
 public function onAddSubscriber(SubscriberEvent $event)
 {
     $subscriber = $event->getSubscriber();
     foreach ($this->formTypesFromConfig as $formTypeName => $formTypeConfig) {
         if ($event->getType() != $formTypeName) {
             continue;
         }
         if (isset($formTypeConfig['storage']['options']['groups'])) {
             $groupsFromConfig = $formTypeConfig['storage']['options']['groups'];
         } else {
             $groupsFromConfig = [];
         }
         foreach ($this->defaultGroups as $defaultGroupToAdd) {
             if (!in_array($defaultGroupToAdd, $groupsFromConfig)) {
                 $groupsFromConfig[] = $defaultGroupToAdd;
             }
         }
         foreach ($groupsFromConfig as $groupToAddFromConfig) {
             $group = $this->em->getRepository(Group::class)->findOneBy(['name' => $groupToAddFromConfig]);
             if ($group === null) {
                 $group = new Group();
                 $group->setName($groupToAddFromConfig);
                 $this->em->persist($group);
             }
             $groupsSubscriberIsIn = $subscriber->getGroup();
             if (!$groupsSubscriberIsIn->contains($group)) {
                 $subscriber->addGroup($group);
                 $this->em->persist($subscriber);
             }
         }
         $this->em->flush();
     }
 }
Ejemplo n.º 2
0
 /**
  * Remove group
  *
  * @param \Enhavo\Bundle\NewsletterBundle\Entity\Group $group
  */
 public function removeGroup(\Enhavo\Bundle\NewsletterBundle\Entity\Group $group)
 {
     $this->group->removeElement($group);
 }