You are here

function user_expire_notify_user in User Expire 8

Same name and namespace in other branches
  1. 7 user_expire.module \user_expire_notify_user()

Displays a message to users with expiring accounts.

Parameters

object $account: (Optional) A user object on which to report.

3 calls to user_expire_notify_user()
UserExpire::doExecute in src/Plugin/RulesAction/UserExpire.php
Expire user.
user_expire_set_expiration in ./user_expire.module
Set a specific user's expiration time.
user_expire_user_login in ./user_expire.module
Implements hook_user_login().

File

./user_expire.module, line 285
Main module file for User expire module.

Code

function user_expire_notify_user($account = NULL) {
  $user = \Drupal::currentUser();
  if (is_null($account)) {
    $account = $user;
  }

  // Only display a message on accounts with a current expiration date.
  if (empty($account->expiration)) {
    return;
  }
  if ($user
    ->id() == $account
    ->id()) {

    // Notify current user that expiration time is in effect.
    \Drupal::messenger()
      ->addMessage(t("Your account's expiration date is set to @date.", [
      '@date' => \Drupal::service('date.formatter')
        ->format($account->expiration),
    ]));
  }
  else {

    // Notify user that expiration time is in effect for this user.
    \Drupal::messenger()
      ->addMessage(t("%name's expiration date is set to @date.", [
      '%name' => $account
        ->getAccountName(),
      '@date' => \Drupal::service('date.formatter')
        ->format($account->expiration),
    ]));
  }
}