コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function share(Post $post)
 {
     if (!$post->getPublished()) {
         return null;
     }
     $contacts = $this->contactProvider->getContacts();
     $now = new \DateTime();
     $from = $this->from;
     $subject = $this->getSubject($now);
     foreach ($contacts as $contact) {
         if (!$contact instanceof ContactInterface) {
             throw new \InvalidArgumentException(sprintf("%s must implement %s.", get_class($contact), ContactInterface::class));
         }
         $template = $this->templating->render('@App/Admin/Post/newsletter.html.twig', array('post' => $post, 'contact' => $contact));
         $to = array($contact->getEmail());
         if ($this->emailSender->send($from, $to, $subject, $template)) {
             $post->setSharedNewsletter($now);
         }
     }
 }