This repository has been archived by the owner on Feb 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
rng.module
122 lines (109 loc) · 3.38 KB
/
rng.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\rng\EventTypeInterface;
use Drupal\Core\Render\Element;
/**
* Implements hook_help().
*/
function rng_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'rng.registration_type.overview':
$output = '<p>' . t('Each registration type is a form that is filled to create a registration. Events can choose which registration type to use for its registrations.') . '</p>';
return $output;
}
}
/**
* Implements hook_entity_access().
*/
function rng_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\rng\RngEntityAccess $rng_access */
$rng_access = \Drupal::service('rng.entity.access');
return $rng_access->hook_entity_access($entity, $operation, $account);
}
/**
* Implements hook_form_alter().
*/
function rng_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'user_admin_permissions') {
// Anonymous 'user' cannot register himself because it is a fake user.
$form['permissions']['rng register self'][AccountInterface::ANONYMOUS_ROLE]['#disabled'] = TRUE;
$form['permissions']['rng register self'][AccountInterface::ANONYMOUS_ROLE]['#access'] = FALSE;
}
}
/**
* Implements hook_cron().
*/
function rng_cron() {
/** @var \Drupal\rng\RngCron $rng_cron */
$rng_cron = \Drupal::service('rng.cron');
$rng_cron->hook_cron();
}
/**
* Implements hook_entity_operation().
*/
function rng_entity_operation(EntityInterface $entity) {
$operations = [];
if ($entity instanceof EventTypeInterface) {
$operations['access_defaults'] = array(
'title' => t('Event access defaults'),
'url' => Url::fromRoute('entity.event_type.access_defaults', [
'event_type' => $entity->id(),
]),
'weight' => 20,
);
}
return $operations;
}
/**
* Implements hook_entity_insert().
*/
function rng_entity_insert(EntityInterface $entity) {
/** @var \Drupal\rng\RngEntityModel $rng_model */
$rng_model = \Drupal::service('rng.entity.model');
$rng_model->hook_entity_postsave($entity, FALSE);
}
/**
* Implements hook_entity_update().
*/
function rng_entity_update(EntityInterface $entity) {
/** @var \Drupal\rng\RngEntityModel $rng_model */
$rng_model = \Drupal::service('rng.entity.model');
$rng_model->hook_entity_postsave($entity, TRUE);
}
/**
* Implements hook_entity_predelete().
*/
function rng_entity_predelete(EntityInterface $entity) {
/** @var \Drupal\rng\RngEntityModel $rng_model */
$rng_model = \Drupal::service('rng.entity.model');
$rng_model->hook_entity_predelete($entity);
}
/**
* Implements hook_theme().
*/
function rng_theme() {
return [
'registration' => [
'render element' => 'elements',
],
];
}
/**
* Prepares variables for registration templates.
*
* Default template: registration.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_registration(array &$variables) {
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}