user_registration_reminder-1.x-dev/user_registration_reminder.module

user_registration_reminder.module
<?php

/**
 * @file
 * Primary module hooks for User Registration Reminder module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 *
 * @inheritdoc
 */
function user_registration_reminder_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.user_registration_reminder':
      $text = file_get_contents(dirname(__FILE__) . "/README.md");
      if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
        $output = '<pre>' . $text . '</pre>';
      }
      else {
        // Use the Markdown filter to render the README.
        $filter_manager = \Drupal::service('plugin.manager.filter');
        $settings = \Drupal::configFactory()
          ->get('markdown.settings')
          ->getRawData();
        $config = ['settings' => $settings];
        $filter = $filter_manager->createInstance('markdown', $config);
        $output = $filter->process($text, 'en');
      }
      $output .= '<p>' . t('See <a href=":documentation">online documentation for the User registration Reminder module</a>.', [':documentation' => 'https://git.drupalcode.org/project/user_registration_reminder/-/blob/1.x/README.md']) . '</p>';
      return $output;
  }
}

/**
 * Implements hook_cron().
 */
function user_registration_reminder_cron() {
  $config = \Drupal::config('user_registration_reminder.settings');
  if (!$config->get('enabled')) {
    return;
  }
  $cronCheckInterval = $config->get('cron_check_interval');
  $lastRun = \Drupal::state()->get('user_registration_reminder.cron_last_run_timestamp', 0);
  // Only execute in the given interval:
  if (($lastRun + $cronCheckInterval) <= time()) {
    /** @var Manager $userRegistrationReminderManager */
    $userRegistrationReminderManager = \Drupal::service('user_registration_reminder.manager');
    $userRegistrationReminderManager->runRegistrationReminder();
    \Drupal::state()->set('user_registration_reminder.cron_last_run_timestamp', time());
  }

}

/**
 * Implements hook_mail().
 */
function user_registration_reminder_mail($key, &$message, $params) {
  switch ($key) {
    case 'user_registration_reminder':
      $message['from'] = \Drupal::config('system.site')->get('mail');
      $message['subject'] = $params['subject'] ?? [];
      $message['body'][] = $params['body'] ?? [];
      $message['headers'] = $params['headers'] ?? [];
      break;
  }
}

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

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