-
Notifications
You must be signed in to change notification settings - Fork 6
/
fixtures.module
80 lines (74 loc) · 2.21 KB
/
fixtures.module
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
<?php
/**
* Sandbox module that creates nodes/menu items/taxonomy items from a simple yaml file
* for testing and initial content if you develop in a clean-build environment.
*
* _ _(o)_(o)_ _
* ._\`:_ F S M _:' \_,
* / (`---'\ `-.
* ,-` _) (_,
*
*/
$includes = array(
'fixtures.node',
'fixtures.menu',
'fixtures.user',
);
foreach ($includes as $include) {
module_load_include('inc', 'fixtures', $include);
}
/**
* implementation of hook_menu()
*/
function fixtures_menu() {
$items = array();
$items['debug_menus'] = array(
'title' => 'debugging fixtures',
'description' => 'bogus function for debugging fixtures',
'page callback' => 'fixtures_create_menus',
'access arguments' => array('access content'),
'file' => 'fixtures.menu.inc'
);
$items['debug_nodes'] = array(
'title' => 'debugging fixtures',
'description' => 'bogus function for debugging fixtures',
'page callback' => 'fixtures_create_nodes',
'access arguments' => array('access content'),
'file' => 'fixtures.node.inc'
);
return $items;
}
/**
* Load the spyc library.
*/
function _fixtures_load_spyc_library() {
// @TODO check if the spyc library is installed. Throw error in system report if the spyc library is missing
$lib_dir = libraries_get_path('spyc');
include_once($lib_dir . '/spyc.php');
}
function fixtures_load_yaml($path) {
_fixtures_load_spyc_library();
return Spyc::YAMLLoad($path);
}
/**
* This function will fetch the YAML files starting with the $type variable and return an array.
*/
function fixtures_get_fixtures($type) {
// @todo make this function also search the sites/[domain] folders, now it's only looking in sites/all
$fixtures = array();
$directory = 'sites/all/fixtures';
if (is_dir($directory) && $handle = opendir($directory)) {
while (($file = readdir($handle)) !== FALSE) {
$file_array = explode('.', $file);
if (end($file_array) == 'yaml') {
$filename_parts = explode('--', reset($file_array));
if ($filename_parts[0] === $type) {
$yaml_file = $directory . '/' . $file;
$fixtures[] = fixtures_load_yaml($yaml_file);
}
}
}
closedir($handle);
}
return $fixtures;
}