gentle_user_reminder-4.0.0/gentle_user_reminder.module

gentle_user_reminder.module
<?php

/**
 * @file
 * Provides a gentle user reminder entity type.
 */

use Drupal\Core\Render\Element;
use Drupal\user\UserInterface;

/**
 * Implements hook_theme().
 */
function gentle_user_reminder_theme() {
  return [
    'gentle_user_reminder' => [
      'render element' => 'elements',
    ],
  ];
}

/**
 * Prepares variables for gentle user reminder templates.
 *
 * Default template: gentle-user-reminder.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An associative array containing the gentle user reminder
 *     information and any
 *     fields attached to the entity.
 *   - attributes: HTML attributes for the containing element.
 */
function template_preprocess_gentle_user_reminder(array &$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
}

/**
 * Implements hook_user_cancel().
 */
function gentle_user_reminder_user_cancel($edit, UserInterface $account, $method) {
  switch ($method) {
    case 'user_cancel_block_unpublish':
      // Unpublish gentle user reminders.
      $storage = \Drupal::entityTypeManager()->getStorage('gentle_user_reminder');
      $gentle_user_reminder_ids = $storage->getQuery()
        ->condition('uid', $account->id())
        ->condition('status', 1)
        ->execute();
      foreach ($storage->loadMultiple($gentle_user_reminder_ids) as $gentle_user_reminder) {
        $gentle_user_reminder->set('status', FALSE);
        $gentle_user_reminder->save();
      }
      break;

    case 'user_cancel_reassign':
      // Anonymize gentle user reminders.
      $storage = \Drupal::entityTypeManager()->getStorage('gentle_user_reminder');
      $gentle_user_reminder_ids = $storage->getQuery()
        ->condition('uid', $account->id())
        ->execute();
      foreach ($storage->loadMultiple($gentle_user_reminder_ids) as $gentle_user_reminder) {
        $gentle_user_reminder->setOwnerId(0);
        $gentle_user_reminder->save();
      }
      break;
  }
}

/**
 * Implements hook_ENTITY_TYPE_predelete() for user entities.
 */
function gentle_user_reminder_user_predelete(UserInterface $account) {
  // Delete gentle user reminders.
  $storage = \Drupal::entityTypeManager()->getStorage('gentle_user_reminder');
  $gentle_user_reminder_ids = $storage->getQuery()
    ->condition('uid', $account->id())
    ->execute();
  $gentle_user_reminders = $storage->loadMultiple($gentle_user_reminder_ids);
  $storage->delete($gentle_user_reminders);
}

/**
 * Implements hook_cron().
 */
function gentle_user_reminder_cron() {
  $emails_sent = \Drupal::service('gentle_user_reminder.cron')->reminderDateCron();
}

/**
 * Implements hook_mail().
 */
function gentle_user_reminder_mail($key, &$message, $params) {
  switch ($key) {
    case 'reminder_email':
      $system_site_config = \Drupal::config('system.site');
      $site_email = $system_site_config->get('mail');
      $message['format'] = 'text/html';
      $message['from'] = $site_email;
      $message['subject'] = $params['subject'];
      $message['body'][] = $params['message'];
      break;
  }
}

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

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