-
Notifications
You must be signed in to change notification settings - Fork 1
/
plug_config.install
56 lines (52 loc) · 1.42 KB
/
plug_config.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
<?php
/**
* @file
* Install hooks implementation.
*/
use Drupal\plug_config\Plugin\PlugConfigManager;
/**
* Implements hook_schema().
*/
function plug_config_schema() {
if (!module_exists('plug_config')) {
return NULL;
}
// Get the definitions even for disabled modules.
$definitions = PlugConfigManager::create('cache', TRUE)->getDefinitions();
$schema = array();
foreach ($definitions as $definition) {
if (!class_exists($definition['class'])) {
// The class is in a disabled module and xautoload will not find it on its
// own. Load the class.
plug_config_load_class($definition['class'], $definition['module']);
}
$schema[$definition['id']] = call_user_func(array($definition['class'], 'schema'));
}
return $schema;
}
/**
* Loads a PSR-4 class file.
*
* @param string $class
* The namespaced class name.
* @param string $module
* The name of the module containing the class.
* @param string $extension
* The extesion of the file to load.
*/
function plug_config_load_class($class, $module, $extension = 'php') {
$parts = explode('\\', $class);
while (count($parts)) {
$part = array_shift($parts);
if ($part == $module) {
break;
}
}
if (empty($parts)) {
return;
}
$path = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . '/src/' . implode('/', $parts) . '.' . $extension;
if (file_exists($path)) {
require_once $path;
}
}