Skip to content

Commit

Permalink
Issue #503: Render links in asset-updated emails, same as in review-r…
Browse files Browse the repository at this point in the history
…eminder emails.
  • Loading branch information
danhgov committed Jun 27, 2024
1 parent 1b0690b commit 3004d74
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions html/modules/custom/bc_dc/bc_dc.module
Original file line number Diff line number Diff line change
Expand Up @@ -385,41 +385,39 @@ function bc_dc_node_update(NodeInterface $entity): void {
}
}

$logger = \Drupal::logger('bc_dc');

// No recipients.
if (!$send_to) {
$context = [
'@nid' => $entity->id(),
];
\Drupal::logger('bc_dc')->notice('No messages to send when updating data_set @nid.', $context);
$logger->notice('No messages to send when updating data_set @nid.', ['@nid' => $entity->id()]);
return;
}

// Send the notifications.
//
// Message subject.
$subject = t('A asset you have bookmarked has been updated');
$subject = t('An asset you have bookmarked has been updated');
// Message body.
$context = [

// The URL goes through user/login since we are emailing this
// out to people who may not be logged in yet.
$body = t("The following asset has been updated:\n* [@title](@asset_url_via_login)", [
'@title' => $entity->getTitle(),
'@link' => $entity->toUrl('canonical', ['absolute' => TRUE])->toString(),
];
$body = t('The following asset has been updated:
@title
@link', $context);
'@asset_url_via_login' => Url::fromRoute('user.login', [], [
'query' => ['destination' => '/node/' . $entity->id()],
'absolute' => TRUE,
])->toString(),
]);
// Send the message and log the result.
$success = GcNotifyApiService::sendMessage($send_to, $subject, $body);
if ($success) {
$context = [
$logger->notice('Sent message to @count users when updating data_set @nid.', [
'@count' => count($send_to),
'@nid' => $entity->id(),
];
\Drupal::logger('bc_dc')->notice('Sent message to @count users when updating data_set @nid.', $context);
]);
}
else {
$context = [
'@nid' => $entity->id(),
];
\Drupal::logger('bc_dc')->error('Failed sending message when updating data_set @nid.', $context);
$logger->error('Failed sending message when updating data_set @nid.', ['@nid' => $entity->id()]);
}
}

Expand Down

0 comments on commit 3004d74

Please sign in to comment.