work_time-1.0.x-dev/modules/fingerprint/fingerprint.module

modules/fingerprint/fingerprint.module
<?php

/**
 * @file
 * Primary module hooks for fingerprint module.
 */

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

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

/**
 * Prepares variables for work time fingerprint templates.
 *
 * Default template: fingerprint.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An associative array containing the work time fingerprint
 *     information and any fields attached to the entity.
 *   - attributes: HTML attributes for the containing element.
 */
function template_preprocess_fingerprint(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 fingerprint_user_cancel($edit, UserInterface $account, $method) {
  switch ($method) {
    case 'user_cancel_block_unpublish':
      // Unpublish work time fingerprints.
      $storage = \Drupal::entityTypeManager()->getStorage('fingerprint');
      $fingerprint_ids = $storage->getQuery()
        ->condition('uid', $account->id())
        ->condition('status', 1)
        ->execute();
      foreach ($storage->loadMultiple($fingerprint_ids) as $fingerprint) {
        $fingerprint->set('status', FALSE);
        $fingerprint->save();
      }
      break;

    case 'user_cancel_reassign':
      // Anonymize work time fingerprints.
      $storage = \Drupal::entityTypeManager()->getStorage('fingerprint');
      $fingerprint_ids = $storage->getQuery()
        ->condition('uid', $account->id())
        ->execute();
      foreach ($storage->loadMultiple($fingerprint_ids) as $fingerprint) {
        $fingerprint->setOwnerId(0);
        $fingerprint->save();
      }
      break;
  }
}

/**
 * Implements hook_ENTITY_TYPE_predelete() for user entities.
 */
function fingerprint_user_predelete(UserInterface $account) {
  // Delete work time fingerprints.
  $storage = \Drupal::entityTypeManager()->getStorage('fingerprint');
  $fingerprint_ids = $storage->getQuery()
    ->condition('uid', $account->id())
    ->execute();
  $fingerprints = $storage->loadMultiple($fingerprint_ids);
  $storage->delete($fingerprints);
}

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

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