You are here

function opigno_set_message in Opigno notifications 8

Same name and namespace in other branches
  1. 3.x opigno_notification.module \opigno_set_message()

Adds notification.

Parameters

int $uid: Notification receiver user id.

string $message: Notification message.

string $url: Url to object mentioned in notification.

Return value

\Drupal\opigno_notification\OpignoNotificationInterface Created notification.

Throws

\Drupal\Core\Entity\EntityStorageException

File

./opigno_notification.module, line 26
Contains opigno_notification.module.

Code

function opigno_set_message($uid, $message, $url = '/notifications') {
  $user = \Drupal::currentUser();
  if ($user
    ->isAnonymous()) {
    \Drupal::messenger()
      ->addMessage($message);
    return NULL;
  }
  else {
    $notification = OpignoNotification::create();
    $notification
      ->setUser($uid);
    $notification
      ->setMessage($message);
    $notification
      ->setUrl($url);
    $notification
      ->save();
    return $notification;
  }
}