commands-1.x-dev/modules/tasks/tasks.module

modules/tasks/tasks.module
<?php

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

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

/**
 * Implements hook_theme().
 */
function tasks_theme(): array {
  return [
    'task' => ['render element' => 'elements'],
  ];
}

/**
 * Prepares variables for tasks templates.
 *
 * Default template: task.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An associative array containing the tasks information and any
 *     fields attached to the entity.
 *   - attributes: HTML attributes for the containing element.
 */
function template_preprocess_task(array &$variables): void {
  $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 tasks_user_cancel($edit, UserInterface $account, $method): void {
  switch ($method) {
    case 'user_cancel_reassign':
      // Anonymize taskss.
      $storage = \Drupal::entityTypeManager()->getStorage('task');
      $task_ids = $storage->getQuery()
        ->condition('uid', $account->id())
        ->accessCheck(FALSE)
        ->execute();
      foreach ($storage->loadMultiple($task_ids) as $task) {
        $task->setOwnerId(0)->save();
      }
      break;
  }
}

/**
 * Implements hook_ENTITY_TYPE_predelete() for user entities.
 */
function tasks_user_predelete(UserInterface $account): void {
  // Delete taskss that belong to this account.
  $storage = \Drupal::entityTypeManager()->getStorage('task');
  $task_ids = $storage->getQuery()
    ->condition('uid', $account->id())
    ->accessCheck(FALSE)
    ->execute();
  $storage->delete(
    $storage->loadMultiple($task_ids)
  );
  // Delete old revisions.
  $task_ids = $storage->getQuery()
    ->allRevisions()
    ->condition('uid', $account->id())
    ->accessCheck(FALSE)
    ->execute();
  foreach (array_keys($task_ids) as $revision_id) {
    $storage->deleteRevision($revision_id);
  }
}

/**
 * Implements hook_entity_bundle_info_alter().
 */
function tasks_entity_bundle_info_alter(array &$bundles): void {
  if (isset($bundles['task']['verify_site'])) {
    // phpcs:ignore Drupal.Classes.FullyQualifiedNamespace.UseStatementMissing
    $bundles['task']['verify_site']['class'] = \Drupal\tasks\Entity\Task\VerifySiteTask::class;
  }
}

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

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