You are here

public function NotificationsController::getNotificationListCallback in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_creator/src/Controller/NotificationsController.php \Drupal\activity_creator\Controller\NotificationsController::getNotificationListCallback()
  2. 8.7 modules/custom/activity_creator/src/Controller/NotificationsController.php \Drupal\activity_creator\Controller\NotificationsController::getNotificationListCallback()
  3. 8.8 modules/custom/activity_creator/src/Controller/NotificationsController.php \Drupal\activity_creator\Controller\NotificationsController::getNotificationListCallback()
  4. 10.3.x modules/custom/activity_creator/src/Controller/NotificationsController.php \Drupal\activity_creator\Controller\NotificationsController::getNotificationListCallback()
  5. 10.1.x modules/custom/activity_creator/src/Controller/NotificationsController.php \Drupal\activity_creator\Controller\NotificationsController::getNotificationListCallback()
  6. 10.2.x modules/custom/activity_creator/src/Controller/NotificationsController.php \Drupal\activity_creator\Controller\NotificationsController::getNotificationListCallback()

Get the notification list.

Return value

\Drupal\Core\Ajax\AjaxResponse Returns a render array list of notifications.

1 string reference to 'NotificationsController::getNotificationListCallback'
activity_creator.routing.yml in modules/custom/activity_creator/activity_creator.routing.yml
modules/custom/activity_creator/activity_creator.routing.yml

File

modules/custom/activity_creator/src/Controller/NotificationsController.php, line 67

Class

NotificationsController
Notifications controller.

Namespace

Drupal\activity_creator\Controller

Code

public function getNotificationListCallback() : AjaxResponse {

  // The data to display, will be the view.
  $view = Views::getView('activity_stream_notifications');
  $view
    ->setDisplay('block_1');
  $rendered_view = $view
    ->render();

  // Create a response.
  $response = new AjaxResponse();

  // Attach the view before marking the notification as seen.
  // This makes sure to render the correct background color of notifications.
  // @see social/modules/custom/activity_creator/activity.page.inc L#117
  $response
    ->addCommand(new HtmlCommand('.js-notification-center-wrapper', $rendered_view));

  // Update the notification count to mark as seen.
  $notification_count = $this->activities
    ->markAllNotificationsAsSeen($this
    ->currentUser()) ? 0 : count($this->activities
    ->getNotifications($this
    ->currentUser()));
  $response
    ->addCommand(new HtmlCommand('.notification-bell .badge', $notification_count));
  return $response;
}