-
Notifications
You must be signed in to change notification settings - Fork 0
/
votings_renders.install
73 lines (64 loc) · 2 KB
/
votings_renders.install
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
<?php
/**
*
* @file
* Install, update and uninstall functions for the votings_renders module.
*/
/**
* Implements hook_install().
*/
function votings_renders_install() {
\Drupal::messenger()->addStatus(__FUNCTION__);
$reactions = _votings_renders_get_reactions();
$voteTypeStorage = \Drupal::service('entity_type.manager')->getStorage('vote_type');
// Create reactions.
$voteTypes = $voteTypeStorage->loadMultiple($voteTypeStorage->getQuery()->accessCheck()->condition('id', array_keys($reactions), 'IN')->execute());
foreach ($reactions as $key => $label) {
$voteType = empty($voteTypes[$key]) ? $voteTypeStorage->create([
'id' => $key,
'label' => $label,
'value_type' => 'points',
'description' => 'Automatically created reaction'
]) : $voteTypes[$key];
$voteType->save();
}
}
/**
* Implements hook_uninstall().
*/
function votings_renders_uninstall() {
\Drupal::messenger()->addStatus(__FUNCTION__);
$reactions = _votings_renders_get_reactions();
$voteTypeStorage = \Drupal::service('entity_type.manager')->getStorage('vote_type');
// Remove reactions.
$voteTypes = $voteTypeStorage->loadMultiple($voteTypeStorage->getQuery()->accessCheck()->condition('id', array_keys($reactions), 'IN')->execute());
foreach ($voteTypes as $voteType) {
$voteType->delete();
}
}
/**
* Implements hook_requirements().
*/
function votings_renders_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$value = mt_rand(0, 100);
$requirements['votings_renders_status'] = [
'title' => t('votings_renders status'),
'value' => t('votings_renders value: @value', [
'@value' => $value
]),
'severity' => $value > 50 ? REQUIREMENT_INFO : REQUIREMENT_WARNING
];
}
return $requirements;
}
/**
* Helper function to return default reactions.
*/
function _votings_renders_get_reactions() {
return [
"votings_renders_favorite" => "Definie en favorite",
"votings_renders_note" => "Note de l'entite"
];
}