monster_menus-9.0.x-dev/modules/mm_alert/mm_alert.module

modules/mm_alert/mm_alert.module
<?php

/**
 * @file
 * Display system alerts.
 */

use Drupal\Core\Config\Config;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Render\Element;
use Drupal\user\Entity\User;

/**
 * Implements hook_mm_config_alter().
 */
function mm_alert_mm_config_alter(&$form, Config $settings) {
  $form['mm_node']['nodes-alert_frequency'] = [
    '#type' => 'select',
    '#title' => t('Frequency of system alerts'),
    '#config_target' => 'monster_menus.settings:nodes.alert_frequency',
    '#options' => [
      'once' => t('Show only once'),
      'login' => t('Show at every login'),
      'constantly' => t('Show at every page load')
    ],
  ];
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function mm_alert_form_node_alert_form_alter(&$form) {
  foreach (Element::children($form) as $child) {
    if ($form['#type'] == 'vertical_tabs') {
      unset($form[$child]['#open']);
    }
  }
  $form['publishing']['#weight'] = 19;
  $form['publishing']['#open'] = TRUE;
  $form['publish_on']['#required'] = TRUE;
  $form['publish_on']['#description'] = '';
  $form['publish_on']['#default_value'] = DrupalDateTime::createFromTimestamp(mm_request_time());
}

/**
 * Implements hook_page_bottom().
 */
function mm_alert_page_bottom(array &$page_bottom) {
  $user = \Drupal::currentUser();
  if ($user->isAnonymous()) {
    return;
  }

  // Checking for alerts is pretty expensive, so don't bother if the frequency
  // is 'login' and the user has already been alerted.
  if (empty($_SESSION['mm_node_displayed_alert']) || mm_get_setting('nodes.alert_frequency') != 'login') {
    // Use a placeholder so that the content is dynamically created with every
    // page load.
    $page_bottom['#attached']['placeholders']['mm_alert']['#lazy_builder'] = ['mm_alert.lazy_builders:getPlaceholder', []];
    $page_bottom['mm_alert'] = ['#markup' => ':mm_alert'];
  }
}

/**
 * Implements hook_user_logout().
 */
function mm_alert_user_logout(User $account) {
  // The access field is used by mm_alert_page_bottom(), but only gets updated
  // at most every 180 seconds. Update it now, so that it's accurate when the
  // user next logs-in.
  $account->setLastAccessTime(mm_request_time())->save();
}

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

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