public function RngContact::applyIdentity in RNG Contact 8
Inserts the identity into the message.
Parameters
\Drupal\courier\ChannelInterface $message: The message. Passed by reference.
EntityInterface $identity: The identity.
Throws
\Drupal\courier\Exception\IdentityException Thrown when an identity cannot be applied. Message is discarded, it does not stop creation of remaining messages in collection.
Overrides IdentityChannelPluginInterface::applyIdentity
File
- src/
Plugin/ IdentityChannel/ CourierEmail/ RngContact.php, line 27
Class
- RngContact
- Supports rng_contact entities.
Namespace
Drupal\rng_contact\Plugin\IdentityChannel\CourierEmailCode
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.');
}
}