-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasyddb_ee_pdf.module
More file actions
executable file
·131 lines (117 loc) · 3.22 KB
/
easyddb_ee_pdf.module
File metadata and controls
executable file
·131 lines (117 loc) · 3.22 KB
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
<?php
/**
* @file
* A custom module for Drupal 7, named 'easyddb_ee_pdf'.
*/
/**
* Implements hook_help().
*/
function easyddb_ee_pdf_help($path, $arg) {
if ($path == 'admin/help#easyddb_ee_pdf') {
return t('Module for generating events list as PDF file.');
}
}
/**
* Implements hook_menu().
*/
function easyddb_ee_pdf_menu(): array {
$items = [];
$items['admin/content/pdf'] = [
'title' => 'Events PDF',
'page callback' => 'drupal_get_form',
'page arguments' => ['easyddb_ee_pdf_generate_pdf_form'],
'access arguments' => array('generate events pdf'),
'type' => MENU_LOCAL_TASK,
'file' => 'easyddb_ee_pdf.pdf.inc',
];
return $items;
}
/**
* Implements hook_permission().
*/
function easyddb_ee_pdf_permission(): array {
return [
'generate events pdf' => [
'title' => t('Generate events list as PDF'),
'description' => t('Check this to allow access to the page to generate events list as a PDF file.'),
],
];
}
/**
* Implements hook_theme().
*/
function easyddb_ee_pdf_theme(): array {
return array(
'ee_pdf_intro' => array(
'variables' => array(
'title' => NULL,
'intro' => NULL,
),
'template' => 'templates/ee_pdf_intro',
),
'ee_pdf_library_events' => array(
'variables' => array(
'library' => NULL,
'events' => NULL,
),
'template' => 'templates/ee_pdf_library_events',
),
'ee_pdf_event' => array(
'variables' => array(
'event' => NULL,
),
'template' => 'templates/ee_pdf_event',
),
'ee_pdf_header' => array(
'variables' => array(
'title' => NULL,
),
'template' => 'templates/ee_pdf_header',
),
'ee_pdf_footer' => array(
'variables' => array(
'title' => NULL,
),
'template' => 'templates/ee_pdf_footer',
),
);
}
/**
* Process the events list into a markup before it gets to the template.
*/
function template_preprocess_ee_pdf_library_events(array &$variables) {
$events = $variables['events'];
$events_list = [];
foreach ($events as $event) {
$events_list[] = theme('ee_pdf_event', ['event' => $event]);
}
$variables['events_list'] = implode('', $events_list);
}
/**
* Implements template_preprocess_HOOK().
*/
function template_preprocess_ee_pdf_event(array &$variables) {
$event = $variables['event'];
$event_date = field_get_items('node', $event, 'field_ding_event_date');
$event_date = $event_date[0] ?? '';
if ($event_date['value']) {
$event_date_obj = (DateTime::createFromFormat(
'Y-m-d H:i:s',
$event_date['value'],
(new DateTimeZone($event_date['timezone_db']))
));
$event_date = $event_date_obj
->setTimezone((new DateTimeZone($event_date['timezone'])))
->format('Y-m-d H:i:s');
}
$variables['event_date'] = $event_date;
$event_location = field_get_items('node', $event, 'field_ding_event_location');
$variables['event_location'] = implode(', ',
array_filter([
$event_location[0]['thoroughfare'] ?? '',
$event_location[0]['locality'] ?? '',
])
);
$event_description = field_get_items('node', $event, 'field_ding_event_body');
$variables['event_description'] = $event_description[0]['safe_value'] ?? '';
}