-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevshop_task.module
102 lines (94 loc) · 3.1 KB
/
devshop_task.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?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;
}