-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbook_bundle.module
executable file
·97 lines (86 loc) · 2.31 KB
/
book_bundle.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
<?php
/**
* @file
* Primary module hooks for Book Bundle module
*/
use Drupal\book_bundle\content\ContentManager;
use Drupal\Core\Render\Element;
use Drupal\user\UserInterface;
/**
* Implements hook_theme().
*/
function book_bundle_theme()
{
return [
'book' => [
'render element' => 'elements',
],
'chapter' => [
'render element' => 'elements',
],
'chapters' => [
'variables' => [
'chapters' => []
],
],
];
}
/**
* Prepares variables for book templates
*
* Default template: book.html.twig
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the book information and any
* fields attached to the entity
* - attributes: HTML attributes for the containing element
*/
function template_preprocess_book(array &$variables)
{
$variables['view_mode'] = $variables['elements']['#view_mode'];
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
/**
* Prepares variables for chapter templates
*
* Default template: chapter.html.twig
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the chapter information and any
* fields attached to the entity
* - attributes: HTML attributes for the containing element
*/
function template_preprocess_chapter(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 book_bundle_user_cancel($edit, UserInterface $account, $method)
{
$contentManager = \Drupal::classResolver(ContentManager::class);
switch ($method) {
case 'user_cancel_block_unpublish':
$contentManager->deleteAllUserContent($account->id());
break;
case 'user_cancel_reassign':
$contentManager->anonymizeAllUserContent($account->id());
break;
}
}
/**
* Implements hook_ENTITY_TYPE_predelete() for user entities
*/
function book_bundle_user_predelete(UserInterface $account)
{
$contentManager = \Drupal::classResolver(ContentManager::class);
$contentManager->deleteAllUserContent($account->id());
}