Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 4 |
CRAP | n/a |
0 / 0 |
|
crm_case_theme | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
template_preprocess_crm_case | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
crm_case_user_cancel | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
30 | |||
crm_case_user_predelete | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * @file |
5 | * Primary module hooks for CRM Case module. |
6 | */ |
7 | |
8 | use Drupal\Core\Render\Element; |
9 | use Drupal\user\UserInterface; |
10 | |
11 | /** |
12 | * Implements hook_theme(). |
13 | */ |
14 | function crm_case_theme() { |
15 | return [ |
16 | 'crm_case' => [ |
17 | 'render element' => 'elements', |
18 | ], |
19 | ]; |
20 | } |
21 | |
22 | /** |
23 | * Prepares variables for crm case templates. |
24 | * |
25 | * Default template: crm-case.html.twig. |
26 | * |
27 | * @param array $variables |
28 | * An associative array containing: |
29 | * - elements: An associative array containing the case information and any |
30 | * fields attached to the entity. |
31 | * - attributes: HTML attributes for the containing element. |
32 | */ |
33 | function template_preprocess_crm_case(array &$variables) { |
34 | $variables['view_mode'] = $variables['elements']['#view_mode']; |
35 | foreach (Element::children($variables['elements']) as $key) { |
36 | $variables['content'][$key] = $variables['elements'][$key]; |
37 | } |
38 | } |
39 | |
40 | /** |
41 | * Implements hook_user_cancel(). |
42 | */ |
43 | function crm_case_user_cancel($edit, UserInterface $account, $method) { |
44 | switch ($method) { |
45 | case 'user_cancel_block_unpublish': |
46 | // Unpublish crm cases. |
47 | $storage = \Drupal::entityTypeManager()->getStorage('crm_case'); |
48 | $crm_case_ids = $storage->getQuery() |
49 | ->condition('uid', $account->id()) |
50 | ->condition('status', 1) |
51 | ->accessCheck(FALSE) |
52 | ->execute(); |
53 | foreach ($storage->loadMultiple($crm_case_ids) as $crm_case) { |
54 | /** @var \Drupal\crm_case\CrmCaseInterface $crm_case */ |
55 | $crm_case->set('status', FALSE); |
56 | $crm_case->save(); |
57 | } |
58 | break; |
59 | |
60 | case 'user_cancel_reassign': |
61 | // Anonymize crm cases. |
62 | $storage = \Drupal::entityTypeManager()->getStorage('crm_case'); |
63 | $crm_case_ids = $storage->getQuery() |
64 | ->condition('uid', $account->id()) |
65 | ->accessCheck(FALSE) |
66 | ->execute(); |
67 | foreach ($storage->loadMultiple($crm_case_ids) as $crm_case) { |
68 | $crm_case->setOwnerId(0); |
69 | $crm_case->save(); |
70 | } |
71 | break; |
72 | } |
73 | } |
74 | |
75 | /** |
76 | * Implements hook_ENTITY_TYPE_predelete() for user entities. |
77 | */ |
78 | function crm_case_user_predelete(UserInterface $account) { |
79 | /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */ |
80 | $storage = \Drupal::entityTypeManager()->getStorage('crm_case'); |
81 | $crm_case_ids = $storage->getQuery() |
82 | ->condition('uid', $account->id()) |
83 | ->accessCheck(FALSE) |
84 | ->execute(); |
85 | $crm_cases = $storage->loadMultiple($crm_case_ids); |
86 | $storage->delete($crm_cases); |
87 | // Delete old revisions. |
88 | $crm_case_ids = $storage->getQuery() |
89 | ->allRevisions() |
90 | ->condition('uid', $account->id()) |
91 | ->accessCheck(FALSE) |
92 | ->execute(); |
93 | foreach (array_keys($crm_case_ids) as $revision_id) { |
94 | $storage->deleteRevision($revision_id); |
95 | } |
96 | } |