You are here

public function OpignoNotificationController::markRead in Opigno notifications 8

Ajax callback. Marks the notification as read.

1 string reference to 'OpignoNotificationController::markRead'
opigno_notification.routing.yml in ./opigno_notification.routing.yml
opigno_notification.routing.yml

File

src/Controller/OpignoNotificationController.php, line 34

Class

OpignoNotificationController
Provides the controller for OpignoNotification entity pages.

Namespace

Drupal\opigno_notification\Controller

Code

public function markRead(OpignoNotificationInterface $opigno_notification = NULL) {
  if ($opigno_notification === NULL) {
    throw new NotFoundHttpException();
  }
  $uid = \Drupal::currentUser()
    ->id();
  if ($opigno_notification
    ->getUser() !== $uid) {
    throw new AccessDeniedHttpException();
  }
  $opigno_notification
    ->setHasRead(TRUE);
  $opigno_notification
    ->save();
  return new JsonResponse([]);
}