-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathislandora_rdm.module
executable file
·109 lines (96 loc) · 3.28 KB
/
islandora_rdm.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
<?php
/**
* @file
* Module file.
*/
use \Drupal\block\Entity\Block;
use \Drupal\Core\Session\AccountInterface;
use \Drupal\Core\Access\AccessResult;
use \Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\media\Entity\Media;
/**
* Implements hook_theme().
*/
function islandora_rdm_theme() {
return [
'node__islandora_rdm_dataset__search_result' => [
'template' => 'node--islandora-rdm-dataset--search-result',
'preprocess functions' => ['islandora_rdm_search_result_preprocess'],
'base hook' => 'node',
],
'media__islandora_rdm_interview__teaser' => [
'template' => 'media--islandora-rdm-interview--teaser',
'preprocess functions' => ['islandora_rdm_interview_preprocess'],
'base hook' => 'media',
],
];
}
/**
* Preprocess function for search result display. Get the abstract description and put it in $variables.
*/
function islandora_rdm_search_result_preprocess(&$variables) {
foreach ($variables['node']->get('field_rdm_description')->referencedEntities() as $description) {
$type = $description->get('field_rdm_description_type')->getString();
$abs_description = $description->get('field_rdm_description')->getString();
if ($type == 'Abstract' && trim($abs_description) != "") {
$variables['rdm_abstract'] = "Abstract: " . $abs_description;
}
}
}
function islandora_rdm_preprocess_media__islandora_rdm_interview__teaser(&$variables) {
# ksm($variables);
$media = $variables['media'];
$items = [];
$captions = [];
$recording_field = $media->get('field_interview_compressed_audio')->entity;
if (!empty($recording_field)) {
$items[] = file_create_url($recording_field->getFileUri());
}
$caption_field = $media->get('field_interview_vtt_file')->entity;
if (!empty($caption_field)) {
$captions_item = file_create_url($caption_field->getFileUri());
$captions[] = [
'src' => $captions_item,
'kind' => 'captions',
'srclang' => $media->language,
'label' => 'Captions',
];
}
$variables['interview'] = [
'#theme' => 'videojs',
'#items' => $items,
'#captions' => $captions,
'#player_attributes' => ['controls' => TRUE, 'width' => 500, 'height' => 400, 'poster' => base_path() . "core/themes/classy/images/icons/audio-x-generic.png"],
'#attached' => [
'library' => ['videojs/videojs'],
],
];
}
/**
* @param \Drupal\block\Entity\Block $block
* @param $operation
* @param \Drupal\Core\Session\AccountInterface $account
* @return \Drupal\Core\Access\AccessResultForbidden
*/
function islandora_rdm_block_access(Block $block, $operation, AccountInterface $account) {
//Replace entity.manager with entity.field.manager if you need to uncomment this.
/* if ($operation == 'view' && $block->getPluginId() == 'views_exposed_filter_block:solr_search_content-page_1') {
$view = \Drupal::service('entity.manager')->getStorage('view')->load('solr_search_content');
if (!$view->status()) {
return AccessResult::forbidden();
}
} */
}
/**
* Implements hook_node_delete().
*/
function islandora_rdm_node_delete(NodeInterface $node) {
if ($node->bundle() == 'islandora_rdm_dataset') {
$utils = \Drupal::service('islandora.utils');
$media = $utils->getMedia($node);
foreach ($media as $victim) {
$victim->delete();
}
}
}