You are here

public function ContactEmail::getRecipients in Contact Emails 8

Get the email recipient(s).

Parameters

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

Return value

array The recipient(s) of the email.

Overrides ContactEmailInterface::getRecipients

File

src/Entity/ContactEmail.php, line 397

Class

ContactEmail
Defines the Contact Email entity.

Namespace

Drupal\contact_emails\Entity

Code

public function getRecipients(MessageInterface $message) {
  $recipients = [];
  $type = $this
    ->get('recipient_type')->value;
  switch ($type) {
    case 'submitter':
      $recipients = $this
        ->getEmailFromSenderMail($message);
      break;
    case 'field':
      $field = $this
        ->get('recipient_field')->value;
      $recipients = $this
        ->getEmailFromField($message, $field);
      break;
    case 'reference':
      $field = $this
        ->get('recipient_reference')->value;
      $recipients = $this
        ->getEmailFromReferencedField($message, $field);
      break;
    case 'default':
      $recipients[] = \Drupal::config('system.site')
        ->get('mail');
      break;
    case 'manual':
    default:
      $recipients = $this
        ->get('recipients')->value;
      $recipients = preg_replace("/\r|\n/", ",", $recipients);
      $recipients = str_replace(';', ',', $recipients);
      $recipients = explode(',', $recipients);
      $recipients = array_map('trim', $recipients);
      break;
  }
  $recipients = is_string($recipients) ? [
    $recipients,
  ] : $recipients;
  array_filter($recipients);
  return $recipients;
}