-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresourcespace.module
More file actions
77 lines (65 loc) · 1.95 KB
/
resourcespace.module
File metadata and controls
77 lines (65 loc) · 1.95 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
<?php
declare(strict_types=1);
function resourcespace_theme()
{
$themes = [
'resourcespace_image_library' => [
'render element' => 'elements',
],
];
return $themes;
}
// Add cron job that runs once a week that removes any download request entites that are older than 7 days
function resourcespace_cron()
{
$state = \Drupal::state();
$last_run = $state->get('resourcespace_cron_last_run', 0);
// Check if it's been more than a week since the last run.
if (
time() - $last_run >= 7 * 24 * 60 * 60
) {
$query = \Drupal::entityQuery('resourcespace_download_request')
->condition('created', strtotime('-7 days'), '<')->accessCheck(FALSE);
$ids = $query->execute();
$storage = \Drupal::entityTypeManager()->getStorage('resourcespace_download_request');
$entities = $storage->loadMultiple($ids);
$storage->delete($entities);
// Update the last run time.
$state->set('resourcespace_cron_last_run', time());
}
}
// function resourcespace_library_info_build()
function resourcespace_library_info_build()
{
$manifest = (array)(json_decode(file_get_contents(__DIR__ . '/resourcespace-browser/dist/.vite/manifest.json')));
$js = [];
$css = ['theme' => []];
// foreach ($manifest['files'] as $file => $path) {
foreach ($manifest as $entry) {
$matches = [];
if ($extension_match = preg_match('/.+\.(css|js)$/', $entry->file, $matches)) {
switch ($matches[1]) {
case 'js':
$js['resourcespace-browser/dist/' . $entry->file] = [
'minified' => TRUE,
'preprocess' => FALSE,
];
break;
case 'css':
$css['theme']['resourcespace-browser/dist/' . $entry->file] = [
'preprocess' => FALSE
];
break;
}
}
}
$libraries = [
'app_bundle' => [
'version' => '1.x',
'css' => $css,
'js' => $js,
'dependencies' => ['core/drupalSettings'],
]
];
return $libraries;
}