- Issue created by @chucksimply
- Assigned to shailja179
- Status changed to Needs review
over 1 year ago 6:58am 26 April 2023 - 🇮🇳India shailja179 India
@chucksimply, where are you showing these notification? In block file or some other place you must have written below code.
To add permission for user specific, you can add condition just before notificationlist array like this. Please try this.
if ($content_admin && $end_user == FALSE) { if (!empty($notification->message)) { $notificationlist[] = [ 'id' => $notification->id, 'message' => $notification->message, 'status' => $notification->status, ]; }
- 🇺🇸United States chucksimply
@shailja179 - the notification output is in the default notifications block that comes with the module.
Im not exactly sure how the code you provided will fix the issue.
Shouldn’t the last argument in
$notificationService->logNotification($message, 'create', $node, $refUserAccessId);
determine who receives the notification? Or am I missing something? - Status changed to Active
over 1 year ago 11:58am 26 April 2023 - 🇧🇪Belgium BramDriesen Belgium 🇧🇪
I was looking into a implementation we did and the only difference I noticed was that we casted the user id to be an int. I believe this is default a string? For the rest this should indeed work. I would also suggest moving the message part outside the loop, as you are not setting anything custom in it. Not sure about the token replacement though, I think it would be safer to replace that with the author value of the node that triggered the notification. I also suggest doing that replacement with a $this->t() function.
$user_access_list = $node->get('field_report_user_access')->referencedEntities(); $message = [ 'id' => $node->id(), 'bundle' => 'report', 'content' => '[user:name] created a new private report and gave you access.', 'content_link' => $node->toUrl()->toString(), ]; foreach ($user_access_list as $user) { if (!empty($user)) { // Log the notification for the referenced user. $notificationService = \Drupal::service('notifications_widget.logger'); $notificationService->logNotification($message, 'create', $node, (int) $user->id()); } }
- Issue was unassigned.
- Status changed to Closed: works as designed
over 1 year ago 8:41pm 28 April 2023 - 🇺🇸United States chucksimply
@BramDriesen - Thanks for the response, and feedback on my code. Yes, the default was being output as a string, and the integer suggestion worked.
Although I did test it on a different setup, and the string did actually work... so maybe it was another issue as well? Not sure... so marking as closed / works as designed. Thanks again!