devshop_tasks-1.0.x-dev/devshop_task.module

devshop_task.module
<?php

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

use Drupal\Core\Render\Element;
use Drupal\devshop_task\Entity\Task;
use Drupal\user\UserInterface;

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

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

/**
 * Implements hook_ENTITY_TYPE_predelete() for user entities.
 */
function devshop_task_user_predelete(UserInterface $account) {
  // Delete tasks.
  $storage = \Drupal::entityTypeManager()->getStorage('task');
  $task_ids = $storage->getQuery()
    ->condition('uid', $account->id())
    ->execute();
  $tasks = $storage->loadMultiple($task_ids);
  $storage->delete($tasks);
}


/**
 * Describe the bundles for entity types.
 *
 * @return array
 *   An associative array of all entity bundles, keyed by the entity
 *   type name, and then the bundle name, with the following keys:
 *   - label: The human-readable name of the bundle.
 *   - uri_callback: (optional) The same as the 'uri_callback' key defined for
 *     the entity type in the EntityTypeManager, but for the bundle only. When
 *     determining the URI of an entity, if a 'uri_callback' is defined for both
 *     the entity type and the bundle, the one for the bundle is used.
 *   - translatable: (optional) A boolean value specifying whether this bundle
 *     has translation support enabled. Defaults to FALSE.
 *   - class: (optional) The fully qualified class name for this bundle. If
 *     omitted, the class from the entity type definition will be used. Multiple
 *     bundles must not use the same subclass. If a class is reused by multiple
 *     bundles, an \Drupal\Core\Entity\Exception\AmbiguousBundleClassException
 *     will be thrown.
 *
 * @see \Drupal\Core\Entity\EntityTypeBundleInfo::getBundleInfo()
 * @see hook_entity_bundle_info_alter()
 */
function devshop_task_entity_bundle_info() {
  $bundles['task']['drush'] = [
    'label' => t('Drush Command'),
    'class' => \Drupal\devshop_task\Entity\Bundle\DrushTask::class
  ];
  return $bundles;
}

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

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