-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowntracks.module
142 lines (128 loc) · 3.77 KB
/
owntracks.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* @file
* Main functions of the module.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\owntracks\Entity\OwnTracksLocationInterface;
use Drupal\owntracks\Entity\OwnTracksTransitionInterface;
use Drupal\owntracks\Entity\OwnTracksWaypointInterface;
/**
* Implements hook_entity_extra_field_info().
*/
function owntracks_entity_extra_field_info() {
$fields['owntracks_location']['owntracks_location']['display']['map'] = [
'label' => t('Map'),
'description' => t('Display a map with a location marker.'),
'weight' => -10,
'visible' => TRUE,
];
$fields['owntracks_transition']['owntracks_transition']['display']['map'] = [
'label' => t('Map'),
'description' => t('Display a map with a transition marker.'),
'weight' => -10,
'visible' => TRUE,
];
$fields['owntracks_waypoint']['owntracks_waypoint']['display']['map'] = [
'label' => t('Map'),
'description' => t('Display a map with a waypoint marker.'),
'weight' => -10,
'visible' => TRUE,
];
return $fields;
}
/**
* Implements hook_help().
*/
function owntracks_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.owntracks':
$text = file_get_contents(dirname(__FILE__) . '/README.md');
if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
return '<pre>' . $text . '</pre>';
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
$config = ['settings' => $settings];
$filter = $filter_manager->createInstance('markdown', $config);
return $filter->process($text, 'en');
}
}
return NULL;
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function owntracks_owntracks_location_view(array &$build, OwnTracksLocationInterface $owntracks_location, EntityViewDisplayInterface $display) {
if ($display->getComponent('map')) {
$build['map'] = [
'#theme' => 'owntracks_map',
'#track' => [$owntracks_location->getLocation()],
];
}
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function owntracks_owntracks_transition_view(array &$build, OwnTracksTransitionInterface $owntracks_transition, EntityViewDisplayInterface $display) {
if ($display->getComponent('map')) {
$build['map'] = [
'#theme' => 'owntracks_map',
'#track' => [$owntracks_transition->getLocation()],
];
}
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function owntracks_owntracks_waypoint_view(array &$build, OwnTracksWaypointInterface $owntracks_waypoint, EntityViewDisplayInterface $display) {
if ($display->getComponent('map')) {
$build['map'] = [
'#theme' => 'owntracks_map',
'#track' => [$owntracks_waypoint->getLocation()],
];
}
}
/**
* Implements hook_theme().
*/
function owntracks_theme($existing, $type, $theme, $path) {
return [
'owntracks_location' => [
'render element' => 'content',
],
'owntracks_transition' => [
'render element' => 'content',
],
'owntracks_waypoint' => [
'render element' => 'content',
],
'owntracks_map' => [
'file' => 'owntracks.theme.inc',
'variables' => [
'attributes' => [],
'track' => [],
],
],
];
}
/**
* Implements hook_ENTITY_TYPE_delete().
*/
function owntracks_user_delete(EntityInterface $entity) {
$tables = [
'owntracks_location',
'owntracks_transition',
'owntracks_waypoint',
];
$database = \Drupal::database();
foreach ($tables as $table) {
$database->delete($table)
->condition('uid', $entity->id())
->execute();
}
}