-
Notifications
You must be signed in to change notification settings - Fork 5
/
islandora_bagger_integration.module
140 lines (130 loc) · 4.68 KB
/
islandora_bagger_integration.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
<?php
use Symfony\Component\Yaml\Yaml;
/**
* Implements hook_islandora_bagger_config_file_contents_alter().
*/
function islandora_bagger_integration_islandora_bagger_config_file_contents_alter($nid, &$config_file_contents) {
if (\Drupal::moduleHandler()->moduleExists('context')) {
$utils = \Drupal::service('islandora_bagger_integration.utils');
$context_manager = \Drupal::service('context.manager');
foreach ($context_manager->getActiveReactions('islandora_bagger_integration_config_options') as $reaction) {
// Last one wins.
$options = $reaction->execute();
}
$options_array = preg_split("/\\r\\n|\\r|\\n/", $options);
$options_from_context = array();
foreach ($options_array as $option) {
list($option_key, $option_value) = explode(':', $option, 2);
$options_from_context[trim($option_key)] = trim($option_value);
}
$config = Yaml::parse($config_file_contents);
foreach ($options_from_context as $key => $value) {
// Skip options that have lists as values, process them below.
$skip_keys = array('bag-info', 'drupal_basic_auth', 'drupal_media_tags', 'plugins', 'post_bag_scripts');
if (!in_array($key, $skip_keys)) {
// If key exists in config file, update value; if not, add it as an option.
$config[$key] = $value;
}
}
// Handle 'bag-info' separately since its value is a list of key:value pairs.
if (array_key_exists('bag-info', $config) && array_key_exists('bag-info', $options_from_context)
&& strlen($options_from_context['bag-info'])) {
$config = $utils->addBagInfoTags($config, $options_from_context['bag-info']);
}
// Handle 'plugins' separately since its value is a list of strings.
foreach ($skip_keys as $key) {
if ($key != 'bag-info') {
if (array_key_exists($key, $config) && array_key_exists($key, $options_from_context)
&& strlen($options_from_context[$key])) {
$config = $utils->addListConfigOptions($config, $key, $options_from_context[$key]);
}
}
}
// Reserialize the modified YAML into $config_file_contents.
$config_file_contents = Yaml::dump($config);
}
}
/**
* Implements hook_views_data().
*/
function islandora_bagger_integration_views_data() {
$data = [];
$data['islandora_bagger_integration_bag_log']['table']['group'] = t('Islandora Bagger');
$data['islandora_bagger_integration_bag_log']['table']['base'] = [
'title' => t('Islandora Bagger Integration'),
'help' => t('Log of Bags registered by Islandora Bagger.'),
'query_id' => 'views_query',
];
// Fields.
$data['islandora_bagger_integration_bag_log']['nid'] = [
'title' => t('Node ID'),
'help' => t('The ID of the node the Bag was generated from.'),
'field' => [
'id' => 'numeric',
],
];
$data['islandora_bagger_integration_bag_log']['hash_algorithm'] = [
'title' => t('Hash algorithm'),
'help' => t('The hash/digest algorithm used by in the Bag.'),
'field' => [
'id' => 'standard',
],
];
$data['islandora_bagger_integration_bag_log']['bagit_version'] = [
'title' => t('Bagit version'),
'help' => t('The version of the Bagit spec declared by the Bag.'),
'field' => [
'id' => 'standard',
],
];
$data['islandora_bagger_integration_bag_log']['ip_address'] = [
'title' => t('IP address'),
'help' => t('The IP address of Islandora Bagger.'),
'field' => [
'id' => 'standard',
],
];
$data['islandora_bagger_integration_bag_log']['created'] = [
'title' => t('Timestamp'),
'help' => t('The timestamp when the Bag was registered.'),
'field' => [
'id' => 'numeric',
],
];
$data['islandora_bagger_integration_bag_log']['bag_name'] = [
'title' => t('Bag name'),
'help' => t("The Bag's filename."),
'field' => [
'id' => 'standard',
],
];
$data['islandora_bagger_integration_bag_log']['bag_info'] = [
'title' => t('bag-info.txt contents'),
'help' => t("The contents of the Bag's bag-info.txt file."),
'field' => [
'id' => 'standard',
],
];
$data['islandora_bagger_integration_bag_log']['bag_info'] = [
'title' => t('bag-info.txt contents'),
'help' => t("The contents of the Bag's bag-info.txt file."),
'field' => [
'id' => 'standard',
],
];
$data['islandora_bagger_integration_bag_log']['manifest'] = [
'title' => t('manifest-{algorithm}.txt contents'),
'help' => t("The contents of the Bag's manifest file."),
'field' => [
'id' => 'standard',
],
];
$data['islandora_bagger_integration_bag_log']['fetch'] = [
'title' => t('fetch.txt contents'),
'help' => t("The contents of the Bag's fetch.txt file."),
'field' => [
'id' => 'standard',
],
];
return $data;
}