You are here

protected function ContactEmail::getEmailFromField in Contact Emails 8

Get email address from a field.

Parameters

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

object $field: The target field on the message.

Return value

array An array of emails.

2 calls to ContactEmail::getEmailFromField()
ContactEmail::getRecipients in src/Entity/ContactEmail.php
Get the email recipient(s).
ContactEmail::getReplyTo in src/Entity/ContactEmail.php
Get the reply-to email address.

File

src/Entity/ContactEmail.php, line 505

Class

ContactEmail
Defines the Contact Email entity.

Namespace

Drupal\contact_emails\Entity

Code

protected function getEmailFromField(MessageInterface $message, $field) {
  $results = [];

  // Send to the value of an email field.
  if ($message
    ->hasField($field)) {

    // Email could potentially be a repeating field.
    $emails = $message
      ->get($field)
      ->getValue();
    if ($emails) {
      foreach ($emails as $email) {
        if ($email['value']) {
          $results[] = $email['value'];
        }
      }
    }
  }
  return $results;
}