/**
  * On FormBuilderSubmittedEvent
  *
  * @param FormBuilderSubmittedEvent $event
  */
 public function onFormBuilderSubmittedEvent(FormBuilderSubmittedEvent $event)
 {
     if ($this->modulesSettings->get('Mailmotor', 'automatically_subscribe_from_form_builder_submitted_form', false)) {
         $form = $event->getForm();
         $data = $event->getData();
         $email = null;
         // Check if we have a replyTo email set
         foreach ($form['fields'] as $field) {
             if (array_key_exists('reply_to', $field['settings']) && $field['settings']['reply_to'] === true) {
                 $email = unserialize($data[$field['id']]['value']);
             }
         }
         // Define language
         $language = array_key_exists('language', $form) ? $form['language'] : $this->modulesSettings->get('Core', 'default_language', 'en');
         // We subscribe the replyTo email
         try {
             // Does email exists or not in our mailing list
             $exists = (bool) $this->subscriber->exists($email);
             // We only need to subscribe when not exists
             if (!$exists) {
                 $this->subscriber->subscribe($email, $language, array(), array(), false);
             }
         } catch (NotImplementedException $e) {
             // We do nothing as fallback when no mail-engine is chosen in the Backend
         }
     }
 }
 /**
  * @param mixed $value
  * @param Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     try {
         // The email doesn't exists in the mailing list
         if (!$this->subscriber->exists($value)) {
             $this->context->buildViolation($constraint->notExistsMessage)->addViolation();
         } elseif ($this->subscriber->isUnsubscribed($value)) {
             $this->context->buildViolation($constraint->alreadyUnsubscribedMessage)->addViolation();
         }
         // fallback for when no mail-engine is chosen in the Backend
     } catch (NotImplementedException $e) {
         // do nothing
     }
 }