-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpcx_connect.module
87 lines (76 loc) · 2.38 KB
/
pcx_connect.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
<?php
/**
* @file
* This module enables the integration of PCC content sdk.
*/
use Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
/**
* Implements hook_theme().
*/
function pcx_connect_theme($existing, $type, $theme, $path) {
$hooks['views_pcc_pager'] = [
'variables' => [
'tags' => [],
'quantity' => 9,
'element' => 0,
'parameters' => [],
'cursor' => 0,
],
];
return $hooks;
}
/**
* Implements hook_preprocess_views_pcc_pager().
*/
function pcx_connect_preprocess_views_pcc_pager(&$variables) {
/** @var \Drupal\Core\Pager\PagerManagerInterface $pager_manager */
$pager_manager = \Drupal::service('pager.manager');
$tags = &$variables['tags'];
$cursor = $variables['cursor'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$pager = $pager_manager->getPager($element);
if (!$pager) {
return;
}
$current = $pager->getCurrentPage();
$total = $pager->getTotalPages();
if ($total > 1 && $current > 0) {
$options = [
'query' => $pager_manager->getUpdatedParameters($parameters, $element, $current - 1),
];
$variables['items']['previous']['href'] = Url::fromRoute('<current>', [], $options)->toString();
if (isset($tags[1])) {
$variables['items']['previous']['text'] = $tags[1];
}
$variables['items']['previous']['attributes'] = new Attribute();
}
if ($current < ($total - 1)) {
$options = [
'query' => $pager_manager->getUpdatedParameters($parameters, $element, $current + 1),
];
$options['query']['cursor'] = $cursor;
$variables['items']['next']['href'] = Url::fromRoute('<current>', [], $options)->toString();
if (isset($tags[3])) {
$variables['items']['next']['text'] = $tags[3];
}
$variables['items']['next']['attributes'] = new Attribute();
}
}
/**
* Implements hook_preprocess_views_view().
*/
function pcx_connect_preprocess_views_view(&$variables) {
/** @var \Drupal\views\ViewExecutable $view */
$view = $variables['view'];
$variables['#cache']['contexts'][] = 'route';
if ($view->current_display == 'realtime_preview') {
foreach ($view->result as $row) {
if (!empty($row->previewActiveUntil)) {
$variables['#attached']['drupalSettings']['realtime_preview']['previewActiveUntil'] = $row->previewActiveUntil;
}
}
$variables['#attached']['library'][] = 'pcx_connect/preview-refresh';
}
}