public function OpignoNotificationController::getMessages in Opigno notifications 3.x
Same name and namespace in other branches
- 8 src/Controller/OpignoNotificationController.php \Drupal\opigno_notification\Controller\OpignoNotificationController::getMessages()
Ajax callback. Get messages and its count.
Return value
\Drupal\Core\Ajax\AjaxResponse The response object.
1 string reference to 'OpignoNotificationController::getMessages'
File
- src/
Controller/ OpignoNotificationController.php, line 155
Class
- OpignoNotificationController
- Provides the controller for OpignoNotification entity pages.
Namespace
Drupal\opigno_notification\ControllerCode
public function getMessages() : AjaxResponse {
$response = new AjaxResponse();
$messages_count = $this->pmService
->getUnreadThreadCount();
$notif_count = count($this->notificationsManager
->getUserHeaderNotifications());
// Display the new messages marker if new messages exist.
if ($messages_count) {
$response
->addCommand(new InvokeCommand('.block-notifications__item--messages .marker', 'removeClass', [
'hidden',
]));
}
else {
$response
->addCommand(new InvokeCommand('.block-notifications__item--messages .marker', 'addClass', [
'hidden',
]));
}
// Update notifications block.
$notifications = $this->notificationsManager
->renderUserHeaderNotifications();
$response
->addCommand(new HtmlCommand('.block-notifications__item--notifications .dropdown-menu', $notifications));
if ($notif_count) {
$response
->addCommand(new InvokeCommand('.block-notifications__item--notifications .marker', 'removeClass', [
'hidden',
]));
$response
->addCommand(new InvokeCommand('.block-notifications__item--notifications .dropdown-menu', 'removeClass', [
'hidden',
]));
}
else {
$response
->addCommand(new InvokeCommand('.block-notifications__item--notifications .dropdown-menu', 'addClass', [
'hidden',
]));
$response
->addCommand(new InvokeCommand('.block-notifications__item--notifications .marker', 'addClass', [
'hidden',
]));
}
return $response;
}