public function subscribe($email, LanguageInterface $language = null)
    {
        if (!$this->validateEmail($email)) {
            throw new NewsletterCannotBeAddedException();
        }

        $newsletterSubscription = $this->getSubscription($email);

        if (!($newsletterSubscription instanceof NewsletterSubscriptionInterface)) {
            $newsletterSubscription = $this->newsletterSubscriptionFactory->create();
            $newsletterSubscription
                ->setEmail($email)
                ->setHash($this->hashGenerator->generate())
                ->setLanguage($language);
        }

        $newsletterSubscription->setEnabled(true);

        $this
            ->newsletterEventDispatcher
            ->dispatchSubscribeEvent($newsletterSubscription);

        return $this;
    }
public function subscribe($email, LanguageInterface $language = null)
    {
        if (!$this->validateEmail($email)) {
            throw new NewsletterCannotBeAddedException();
        }

        $newsletterSubscription = $this->getSubscription($email);

        if (!($newsletterSubscription instanceof NewsletterSubscriptionInterface)) {
            $newsletterSubscription = $this->newsletterSubscriptionFactory->create();
            $newsletterSubscription
                ->setEmail($email)
                ->setHash($this->hashGenerator->generate())
                ->setLanguage($language);
        }

        $newsletterSubscription->setEnabled(true);

        $this
            ->newsletterEventDispatcher
            ->dispatchSubscribeEvent($newsletterSubscription);

        return $this;
    }
public function subscribe ( $ email , LanguageInterface $ language = null ) { if ( ! $ this -> validateEmail ( $ email ) ) { throw new NewsletterCannotBeAddedException ( ) ; } $ newsletterSubscription = $ this -> getSubscription ( $ email ) ; if ( ! ( $ newsletterSubscription instanceof NewsletterSubscriptionInterface ) ) { $ newsletterSubscription = $ this -> newsletterSubscriptionFactory -> create ( ) ; $ newsletterSubscription -> setEmail ( $ email ) -> setHash ( $ this -> hashGenerator -> generate ( ) ) -> setLanguage ( $ language ) ; } $ newsletterSubscription -> setEnabled ( true ) ; $ this -> newsletterEventDispatcher -> dispatchSubscribeEvent ( $ newsletterSubscription ) ; return $ this ; }
Subscribe email to newsletter.

@param string            $email    Email
@param LanguageInterface $language The language

@return $this Self object

@throws NewsletterCannotBeAddedException
Subscribe email to newsletter .