-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathckeditor_media_embed.install
More file actions
103 lines (83 loc) · 3.68 KB
/
ckeditor_media_embed.install
File metadata and controls
103 lines (83 loc) · 3.68 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
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
<?php
/**
* @file
* Install file for the CKEditor Media Embed plugin module.
*/
use Drupal\ckeditor_media_embed\AssetManager;
use Drupal\Core\Render\Markup;
/**
* Implements hook_install().
*/
function ckeditor_media_embed_install() {
$version = AssetManager::getCKEditorVersion(\Drupal::service('library.discovery'), \Drupal::service('config.factory'));
if (!AssetManager::pluginsAreInstalled($version)) {
\Drupal::messenger()->addWarning(_ckeditor_media_embed_get_install_instructions());
}
}
/**
* Implements hook_requirements().
*/
function ckeditor_media_embed_requirements($phase) {
$requirements = [];
if ($phase === 'runtime') {
$library_discovery = \Drupal::service('library.discovery');
$config_factory = \Drupal::service('config.factory');
$version = AssetManager::getPluginsVersion($library_discovery, $config_factory);
$plugin_statuses = AssetManager::getPluginsInstallStatuses($version);
$installed_plugins = array_filter($plugin_statuses);
$missing_plugins = array_filter($plugin_statuses, function ($is_installed) {
return !$is_installed;
});
$mixed_version = ($version != AssetManager::getCKEditorVersion($library_discovery, $config_factory));
$has_error = !empty($missing_plugins) || $mixed_version ? TRUE : FALSE;
$value = t('Installed');
if (!empty($missing_plugins)) {
$value = t('Missing plugins');
}
elseif ($mixed_version) {
$value = t('Mixed versions');
}
$requirements["ckeditor_media_embed"] = [
'title' => 'CKEditor Media Embed plugin',
'value' => $value,
'description' => _ckeditor_media_embed_requirments_build_description($installed_plugins, $missing_plugins, $mixed_version),
'severity' => ($has_error) ? REQUIREMENT_ERROR : REQUIREMENT_INFO,
];
}
return $requirements;
}
/**
* Retrieve the requirements description.
*
* @param array $installed_plugins
* An array of our CKEditor plugins that are installed.
* @param array $missing_plugins
* An array of our CKEditor plugins that are missing.
* @param bool $mixed_version
* Determines if we should show the mixed version message.
*
* @return string|\Drupal\Component\Render\MarkupInterface
* A safe string representation of the requirements description.
*/
function _ckeditor_media_embed_requirments_build_description(array $installed_plugins, array $missing_plugins, $mixed_version) {
$description = '';
if (!empty($missing_plugins)) {
$description .= t('The following CKEditor plugins are missing: <strong>%plugins</strong>.', ['%plugins' => implode(', ', array_keys($missing_plugins))]) . '<br />';
$description .= _ckeditor_media_embed_get_install_instructions(FALSE) . '<br />';
}
if (!empty($installed_plugins)) {
$description .= t('The following CKEditor plugins are installed: %plugins.', ['%plugins' => implode(', ', array_keys($installed_plugins))]) . '<br />';
}
if (empty($missing_plugins)) {
if ($mixed_version) {
$description .= t('The installed CKEditor plugins have a different version than the installed CKEditor. Please consider updating the plugins.') . '<br />';
$description .= _ckeditor_media_embed_get_install_instructions(FALSE, TRUE) . '<br />';
}
$installed_plugin_versions = AssetManager::getPluginsInstalledVersion(\Drupal::service('config.factory'));
if (!empty($installed_plugin_versions)) {
$description .= t('Installed plugins version: @version', ['@version' => $installed_plugin_versions]) . '<br />';
}
}
$description .= t('CKEditor version: @version', ['@version' => AssetManager::getCKEditorVersion(\Drupal::service('library.discovery'), \Drupal::service('config.factory'))]);
return Markup::Create($description);
}