-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwireframe_me.module
60 lines (55 loc) · 2.21 KB
/
wireframe_me.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
<? // By Sean Larkin at ThinkShout.com
// Parse wireframe inc files.
require_once('wireframe_me.inc');
/**
* Implementation of Hook_init().
* Check to see if there have been edits to the wireframes config file.
* If so, flush the menu cache to pickup changes. (Note, only works for logged-in page loads.)
*/
function wireframe_me_init() {
$wireframes_file = drupal_get_path('module', 'wireframe_me') . '/wireframes/wireframe_me.wireframes.inc';
$last_stamp = variable_get('wireframe_me_timestamp', '');
$current_stamp = filemtime($wireframes_file);
if (!($last_stamp == $current_stamp)) { // Flush menu cache if changes are picked up.
variable_set('wireframe_me_timestamp', $current_stamp);
menu_rebuild();
}
}
/**
* Implementation of Hook_module_implements_alter(&$implementations, $hook).
* Leveraged to make sure that our wireframed paths lose to real paths.
*/
function wireframe_me_module_implements_alter(&$implementations, $hook) {
if ($hook == 'menu') {
$group = $implementations['wireframe_me']; // Find our implementations w/in the implementations array.
unset($implementations['wireframe_me']); // Unset our implementations.
//Add our implementations back at the top of the stack so that we "lose" to other modules competing for a path.
$implementations = array('wireframe_me' => $group) + $implementations;
}
}
/**
* Implementation of Hook_menu().
* @FIXME - Not sure why we can't set the 'title' => $wireframe['title].
*/
function wireframe_me_menu() {
$wireframes = wireframe_me_load_wireframes(); // Grab and parse our wireframes into an array.
if ($wireframes) { // If an array is returned, create menus. @TODO - Alert logged-in user of failures.
foreach ($wireframes as $path => $wireframe) {
$items[$path] = array(
'title' => 'A wireframe',
'page callback' => 'wireframe_me_content',
'page arguments' => array($wireframe['title'], $wireframe['content']),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
}
}
return $items;
}
/**
* Helper function for setting page body and title of stubbed out wireframes.
*/
function wireframe_me_content($title, $content) {
drupal_set_title(check_plain($title));
return $content;
}