- Issue created by @ryanrobinson_wlu
- 🇧🇪Belgium dieterholvoet Brussels
You could send the mail to the author and CC to the co-authors. According to the CC field description 'multiple email addresses may be separated by commas'.
I would have expected a token like
[webform_submission:source-entity:co_authors]
to already exist automatically, but seems like it doesn't. We should probably look into why the Token module isn't providing a token for that field. - 🇨🇦Canada ryanrobinson_wlu
I've made a custom module that adds a new token like below. You're welcome to use/improve this if you think it would be helpful to others. If you decide to incorporate something like this into the main module, I'd be happy to phase out mine.
From the coauthor_tokens.module file:
<?php /** * @file * Token functions extending node_co_author. */ use Drupal\Core\Render\BubbleableMetadata; use Drupal\user\Entity\User; /** * Implements hook_token_info(). * * Defines tokens. */ function coauthor_tokens_token_info() { $info = []; $info['tokens']['node']['coauthors_email'] = [ 'name' => t("Coauthors' emails."), 'description' => t("The coauthors' email addresses, separated by commas."), ]; return $info; } /** * Implements hook_tokens(). * * Defines values for tokens. */ function coauthor_tokens_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { $replacements = []; foreach ($tokens as $name => $original) { if ($type == "node") { switch ($name) { case 'coauthors_email': $node = $data['node']; if ($node) { $coauthor_emails = []; $coauthors = $node->get('co_authors')->getValue(); foreach ($coauthors as $coauthor) { $coauthor_emails[] = User::load($coauthor['target_id'])->getEmail(); } $replacements[$original] = implode(',', $coauthor_emails); } break; } } } return $replacements; }
- 🇧🇪Belgium dieterholvoet Brussels
It seems like it's not yet possible to automatically provide all user-related tokens for an array of co-authors (see ✨ Need to figure out how to create nested tokens from the array token type Needs review ), so we'll need to define individual tokens per field as @ryanrobinson_wlu does in his example. I'll start a MR.
- 🇧🇪Belgium dieterholvoet Brussels
I added a new
[node:co_authors_email]
token to the MR. To get the email addresses as a comma-separated list, you can use[node:co_authors_email:join]
. Can someone test the MR?