-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwxt_library.install
83 lines (72 loc) · 2.18 KB
/
wxt_library.install
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
<?php
/**
* @file
* Installation and update functions for the WxT Bootstrap Library.
*/
use Drupal\Core\Url;
/**
* Implements hook_requirements().
*/
function wxt_library_requirements($phase) {
$requirements = [];
if ('runtime' == $phase) {
$has_wxt_core = _wxt_library_verify_library('wxt_library', 'wet-boew');
$requirements['wxt'] = [
'title' => t('WxT Library'),
'value' => $has_wxt_core ? t('Enabled') : t('Not found'),
];
if (!$has_wxt_core) {
$requirements['wxt']['severity'] = REQUIREMENT_WARNING;
$wxt_url = Url::fromUri('https://github.com/wet-boew/wet-boew', ['attributes' => ['target' => '_blank']]);
$requirements['wxt']['description'] = [
'#prefix' => ' ',
'#markup' => t('wxt_library module requires <a href=":wxt_link">WxT</a> core jQuery Framework to properly render data.', [':wxt_link' => $wxt_url->toUriString()]),
];
}
}
return $requirements;
}
/**
* Verify that the library files exist.
*
* @param string $extension
* The name of the extension that registered a library.
* @param string $name
* The name of a registered library to retrieve.
*
* @return bool
* TRUE if all files of this library exists, FALSE otherwise
*
* @see https://drupal.org/node/2231385
*/
function _wxt_library_verify_library($extension, $name) {
/** @var Drupal\Core\Asset\LibraryDiscovery $library_discovery */
$library_discovery = \Drupal::service('library.discovery');
$library = $library_discovery->getLibraryByName($extension, $name);
$exist = TRUE;
if ($library['js']) {
foreach ($library['js'] as $js) {
if ($js['type'] == 'file') {
if (!file_exists(DRUPAL_ROOT . '/' . $js['data'])) {
$exist = FALSE;
}
}
}
}
if ($library['css']) {
foreach ($library['css'] as $css) {
if ($css['type'] == 'file') {
if (!file_exists(DRUPAL_ROOT . '/' . $css['data'])) {
$exist = FALSE;
}
}
}
}
if ($library['dependencies']) {
foreach ($library['dependencies'] as $dependency) {
$parts = explode('/', $dependency);
$exist = _wxt_library_verify_library($parts[0], $parts[1]);
}
}
return $exist;
}