You are here

class RngContact in RNG Contact 8

Same name in this branch
  1. 8 src/Entity/RngContact.php \Drupal\rng_contact\Entity\RngContact
  2. 8 src/Plugin/IdentityChannel/CourierEmail/RngContact.php \Drupal\rng_contact\Plugin\IdentityChannel\CourierEmail\RngContact

Supports rng_contact entities.

Plugin annotation


@IdentityChannel(
  id = "identity:rng_contact:courier_email",
  label = @Translation("rng_contact to courier_mail"),
  channel = "courier_email",
  identity = "rng_contact",
  weight = 10
)

Hierarchy

Expanded class hierarchy of RngContact

File

src/Plugin/IdentityChannel/CourierEmail/RngContact.php, line 22

Namespace

Drupal\rng_contact\Plugin\IdentityChannel\CourierEmail
View source
class RngContact implements IdentityChannelPluginInterface {

  /**
   * {@inheritdoc}
   */
  public function applyIdentity(ChannelInterface &$message, EntityInterface $identity) {

    /** @var \Drupal\rng_contact\Entity\RngContactInterface $identity */

    /** @var \Drupal\courier\EmailInterface $message */
    $contact_type = RngContactType::load($identity
      ->bundle());
    $email_field = $contact_type
      ->getCourierEmailField();
    if ($email_field && isset($identity->{$email_field})) {
      $email = $identity->{$email_field};
      if (!empty($email->value)) {
        $message
          ->setRecipientName($identity
          ->label());
        $message
          ->setEmailAddress($email->value);
      }
      else {
        throw new IdentityException('Contact missing email address.');
      }
    }
    else {
      throw new IdentityException('Contact type email field not configured.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RngContact::applyIdentity public function Inserts the identity into the message. Overrides IdentityChannelPluginInterface::applyIdentity