Skip to content

Commit

Permalink
In the social mailer preprocess we set a header but this is dependent…
Browse files Browse the repository at this point in the history
… on if a user can be found, this way it was set it will always return a boolean where it cannot find a user on
  • Loading branch information
Robert Ragas committed Aug 22, 2023
1 parent a46f720 commit f37da24
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion modules/social_features/social_mailer/social_mailer.module
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use Drupal\Core\Link;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface;
use Drupal\social_mailer\Element\SocialMailerTextFormat;
use Drupal\symfony_mailer\AddressInterface;
use Drupal\user\UserInterface;
use Drupal\symfony_mailer\EmailInterface;
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
Expand Down Expand Up @@ -129,7 +130,7 @@ function social_mailer_preprocess_email(array &$variables): void {
}
else {
$to = $email->getTo();
$mail = isset($to[0]) ?? FALSE;
$mail = isset($to[0]) ? _addressesToString($to)[0] : FALSE;
}

if ($mail && ($user = user_load_by_mail($mail)) instanceof UserInterface) {
Expand Down Expand Up @@ -165,6 +166,21 @@ function social_mailer_element_info_alter(array &$info): void {
}
}

/**
* Render array of addresses as array of strings.
*
* @param \Drupal\symfony_mailer\AddressInterface[] $addresses
* An array of Address objects.
*
* @return array
* An array of strings.
*/
function _addressesToString(array $addresses): array {
return array_map(function (AddressInterface $address) {
return $address->getEmail();
}, $addresses);
}

/**
* Implements hook_mailer_builder_info_alter().
*/
Expand Down

0 comments on commit f37da24

Please sign in to comment.