You are here

public function ContactEmail::getReplyTo in Contact Emails 8

Get the reply-to email address.

Parameters

\Drupal\contact\MessageInterface $message: The contact message.

Return value

string The reply-to email address.

Overrides ContactEmailInterface::getReplyTo

File

src/Entity/ContactEmail.php, line 437

Class

ContactEmail
Defines the Contact Email entity.

Namespace

Drupal\contact_emails\Entity

Code

public function getReplyTo(MessageInterface $message) {
  $reply_to = NULL;
  $type = $this
    ->get('reply_to_type')->value;
  switch ($type) {
    case 'submitter':
      $reply_to = $this
        ->getEmailFromSenderMail($message);
      break;
    case 'field':
      $field = $this
        ->get('reply_to_field')->value;
      $reply_to = $this
        ->getEmailFromField($message, $field);
      break;
    case 'reference':
      $field = $this
        ->get('reply_to_reference')->value;
      $reply_to = $this
        ->getEmailFromReferencedField($message, $field);
      break;
    case 'manual':

      // Send to the value of an email field.
      if (!$this
        ->get('reply_to_email')
        ->isEmpty()) {
        $reply_to = $this
          ->get('reply_to_email')->value;
      }
      break;
    case 'default':
    default:
      $reply_to = \Drupal::config('system.site')
        ->get('mail');
      break;
  }

  // We may have an array as a referenced field may be repeating. In that
  // case we take the first email.
  if (is_array($reply_to)) {
    array_filter($reply_to);
    return reset($reply_to);
  }
  else {
    return $reply_to;
  }
}