-
Notifications
You must be signed in to change notification settings - Fork 1
/
compound_viewer.module
68 lines (54 loc) · 1.78 KB
/
compound_viewer.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
<?php
/**
* @file
* Contains compound_viewer.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\Views;
/**
* Implements hook_help().
*/
function compound_viewer_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the compound_viewer module.
case 'help.page.compound_viewer':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Compound Viewer Utils') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_views_pre_view().
*/
function compound_viewer_views_pre_view($view, string $display_id, array $args) {
// If the playlist media view is being rendered
if (($view->id() === 'playlist_item_media') && ($display_id === 'block_1')) {
// Get the current node
$node = \Drupal::routeMatch()->getParameter('node');
$nid = $node->id();
// Get the compound view
$view_children = Views::getView('compound_object_members');
$view_children->setDisplay('block_1');
$view_children->setArguments([$nid]);
$view_children->execute();
$view_result = $view_children->result;
// Get the first member node id of the compound object
$node_id = "";
if (!empty($view_result)) {
foreach ($view_result as $row) {
$node_id = $row->nid;
break;
}
}
// Set the default node when first going to the compound object
$exposed_input = $view->getExposedInput();
$current_uri = \Drupal::request()->getRequestUri();
if (!str_contains($current_uri, 'compound_member_node_id')) {
$exposed_input['compound_member_node_id'] = $node_id;
$view->setExposedInput($exposed_input);
}
$view->element['#attached']['library'][] = 'compound_viewer/compound_viewer.exposed_filter';
}
}