This repository has been archived by the owner on Jan 19, 2018. It is now read-only.
forked from kekkis/image_widget_crop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_widget_crop.install
53 lines (48 loc) · 1.95 KB
/
image_widget_crop.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
<?php
/**
* @file
* Install, update and uninstall functions for the ImageWidgetCrop module.
*/
/**
* Implements hook_requirements().
*/
function image_widget_crop_requirements($phase) {
$error = [];
$config = \Drupal::config('image_widget_crop.settings');
$files = [
'js' => $config->get('settings.library_url'),
'css' => $config->get('settings.css_url')
];
foreach ($files as $type => $file) {
$is_local = parse_url($file, PHP_URL_SCHEME) === NULL && strpos($file, '//') !== 0;
// If libraries module is active check if folder is malformed.
if ($is_local
&& \Drupal::moduleHandler()->moduleExists('libraries')
&& ($info = libraries_detect('cropper'))
&& (!file_exists($info['library path'] . '/dist/cropper.min.' . $type) && !file_exists($info['library path'] . '/cropper.min.' . $type))) {
$error[] = t("<strong>:type</strong> file : Libraries module is active but an error detected with your cropper libraries configuration. To use cropper library with <i>'libraries'</i> module you must have the following structure <i>`:libraries_cropper`</i>", [
':type' => strtoupper($type),
':libraries_cropper' => '/libraries/cropper/dist/cropper.min.' . $type
]);
}
}
$requirements = [];
$requirements['iwc_libraries'] = [
'title' => t('ImageWidgetCrop library'),
'value' => empty($error) ? t('Correctly configured') : t('Files not found'),
];
if (!empty($error)) {
$requirements['iwc_libraries']['severity'] = REQUIREMENT_ERROR;
$requirements['iwc_libraries']['description'][] = [
'#theme' => 'item_list',
'#items' => $error,
];
}
else {
$requirements['iwc_libraries']['severity'] = REQUIREMENT_OK;
$requirements['iwc_libraries']['description'] = t('ImageWidgetCrop libraries files are correctly configured to use <strong>:library</strong> files', [
':library' => !$is_local ? 'CDN' : 'Libraries API',
]);
}
return $requirements;
}