/
recipes.module
154 lines (135 loc) · 4.92 KB
/
recipes.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* @file
* Provides an admin interface for managing recipes.
*/
/**
* Implements hook_menu().
*/
function recipes_menu() {
$items['admin/structure/recipes'] = array(
'title' => 'Recipes',
'page callback' => 'backdrop_get_form',
'page arguments' => array('recipes_admin'),
'access arguments' => array('manage recipes'),
'type' => MENU_NORMAL_ITEM,
'file' => 'recipes.admin.inc',
);
$items['admin/structure/recipes/import/%recipe'] = array(
'title' => 'Import Recipe',
'page callback' => 'recipes_import',
'page arguments' => array(4),
'access arguments' => array('manage recipes'),
'type' => MENU_CALLBACK,
'file' => 'recipes.admin.inc',
);
$items['admin/structure/recipes/export/%recipe'] = array(
'title' => 'Export Recipe',
'page callback' => 'recipes_export',
'page arguments' => array(4),
'access arguments' => array('manage recipes'),
'type' => MENU_CALLBACK,
'file' => 'recipes.admin.inc',
);
$items['admin/structure/recipes/revert/%recipe'] = array(
'title' => 'Revert Recipe',
'page callback' => 'recipes_revert',
'page arguments' => array(4),
'access arguments' => array('manage recipes'),
'type' => MENU_CALLBACK,
'file' => 'recipes.admin.inc',
);
$items['admin/structure/recipes/inspect/%recipe'] = array(
'title' => 'Inspect Recipe',
'page callback' => 'recipes_inspect',
'page arguments' => array(4),
'access arguments' => array('manage recipes'),
'type' => MENU_CALLBACK,
'file' => 'recipes.admin.inc',
);
$items['admin/structure/recipes/remove/%recipe'] = array(
'title' => 'Remove Recipe',
'page callback' => 'recipes_remove',
'page arguments' => array(4),
'access arguments' => array('manage recipes'),
'type' => MENU_CALLBACK,
'file' => 'recipes.admin.inc',
);
return $items;
}
/**
* Magic loader: Loads recipe information.
*/
function recipe_load($project) {
$modules = system_rebuild_module_data();
return array(
'project' => $project,
'name' => $modules[$project]->info['name'],
);
}
/**
* Implements hook_permission().
*/
function recipes_permission() {
return array(
'manage recipes' => array(
'title' => t('Manage recipes'),
'description' => t('Access the recipes overview page, and import recpies.'),
),
'inspect recipes' => array(
'title' => t('Inspect recipes'),
'description' => t('View and manage the technical deails of a recipe.'),
'restrict access' => TRUE,
'warning' => t('People who can inspect recipes will also be able to delete individual config files.'),
),
);
}
/**
* Implements hook_theme().
*/
function recipes_theme() {
return array(
'recipe_fieldset' => array(
'render element' => 'form',
),
);
}
function theme_recipe_fieldset($variables) {
$form = $variables['form'];
// Individual table headers.
$rows = array();
// Iterate through all the recipes, which are children of this fieldset.
foreach (element_children($form) as $key) {
// Stick the key into $module for easier access.
$module = $form[$key];
// Create the row for the table.
$row = array();
$module['#requires'] = array_filter($module['#requires']);
$module['#required_by'] = array_filter($module['#required_by']);
$requires = !empty($module['#requires']);
$required_by = !empty($module['#required_by']);
$requirements = '';
$toggle = '';
// Add the first column: module label and expand/collapse functionality.
$row[] = array('class' => array('module'), 'data' => '<label id="module-' . $key . '" class="module-name table-filter-text-source">' . backdrop_render($module['name']) . '</label>');
// Add the second column: module version number.
$row[] = array('class' => array('version'), 'data' => backdrop_render($module['version']));
// Add the description, along with any modules it requires.
$details = '<div class="text table-filter-text-source"> ' . backdrop_render($module['description']) . '</div>';
// Add the third column: description, along with any modules it requires.
$row[] = array('class' => array('description'), 'data' => $details);
$requirements = '';
if ($requires) {
$requirements .= '<div class="admin-requirements">' . t('Requires:') . ' ' . implode(', ', $module['#requires']) . '</div>';
}
if ($required_by) {
$requirements .= '<div class="admin-requirements">' . t('Required by:') . ' ' . implode(', ', $module['#required_by']) . '</div>';
}
// Add the fourth column: description, along with any modules it requires.
$row[] = array('class' => array('requirements'), 'data' => $requirements);
// Add the fifth column: links (such as configure or permissions) in their own columns.
$row[] = array('data' => backdrop_render($module['links']), 'class' => array('operations'));
$rows[] = $row;
}
return theme('table', array('header' => $form['#header'], 'rows' => $rows));
}