popup_after_login-9.1.x-dev/popup_after_login.module

popup_after_login.module
<?php

/**
 * @file
 * This file is used to write hooks that used in the module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function popup_after_login_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.popup_after_login':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Display pop-up message after user logged in. Provide configurable back-end to write message and shown in pop-up when user is logged in, Only once per login.') . '</p>';
      return $output;

    default:

  }
}

/**
 * Hook_preprocess_page().
 */
function popup_after_login_preprocess_page(&$variables) {
  // Attach JS if needs to popup the message.
  $user = \Drupal::currentUser();
  if ($user) {
    $username = $user->getAccount()->name;
    if ($user && (isset($_SESSION['first_' . $username]) || isset($_SESSION['always_' . $username]))) {
      global $base_url;
      $variables['#attached']['library'][] = 'popup_after_login/popup_after_login_js';
      $variables['#attached']['drupalSettings']['siteBaseUrl'] = $base_url;
    }
  }
}

/**
 * Hook_user_login().
 */
function popup_after_login_user_login($account) {
  $username = $account->getAccountName();
  if (!$account->getLastAccessedTime()) {
    $_SESSION['first_' . $username] = TRUE;
  }
  else {
    $_SESSION['always_' . $username] = TRUE;
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc