-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.module
266 lines (250 loc) · 8.27 KB
/
doc.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/**
* Set global array to configure core entity links
*/
$vars = array (
'#submit_handler' => 'doc_form_alter_submit_handler',
);
$GLOBALS['doc_entities'] = array(
'system_site_information_settings' => array(
'#entity' => 'configuration',
'#id' => 'site',
'#submit_id' => 'site',
)+$vars,
'node_type_form' => array(
'#entity' => 'content_type',
'#fieldset' => 'additional_settings',
'#id' => array('type','#default_value'),
'#submit_id' => array('values','name'),
)+$vars,
'field_ui_field_edit_form' => array(
'#entity' => 'field',
'#fieldset' => 'documentation',
'#id' => array('#field','field_name'),
'#submit_id' => array('values','name'),
)+$vars,
'update_manager_install_form' => array(
'#entity' => 'module',
'#id' => 'module',
'#submit_id' => 'module',
'#submit_handler' => 'doc_module_install_create_documentation',
),
'taxonomy_form_vocabulary' => array(
'#entity' => 'taxonomy',
'#id' => array('vid','#value'),
'#submit_id' => array('values','vid'),
)+$vars,
'block_add_block_form' => array(
'#entity' => 'block',
'#id' => array('delta','#value'),
'#submit_id' => array('values','delta'),
)+$vars,
'block_admin_configure' => array(
'#entity' => 'block',
'#id' => array('delta','#value'),
'#submit_id' => array('values','delta'),
)+$vars,
'menu_edit_menu' => array(
'#entity' => 'menu',
'#id' => array('menu_name','#default_value'),
'#submit_id' => array('values','menu_name'),
)+$vars,
'system_theme_settings' => array(
'#entity' => 'theme',
'#id' => array('var','#value'),
'#submit_id' => array('values','var'),
)+$vars,
'user_admin_role' => array(
'#entity' => 'user_role',
'#id' => array('rid','#value'),
'#submit_id' => array('values','var'),
)+$vars,
'doc_module_create_documentation' => array(
'#entity' => 'module',
'#id' => array('#module_id'),
'#submit_id' => array('#module_id'),
)+$vars,
);
/**
* Implements hook_permission().
*/
function doc_permission() {
return array(
'administer documentation' => array(
'title' => t('Administer documentation'),
'description' => t('Allow editing of documentation by user.'),
),
'view documentation' => array(
'title' => t('View documentation'),
'description' => t('Allow viewing of documentation by user.'),
),
);
}
/**
* Implements hook_help().
*/
function doc_help($path, $arg) {
switch ($path) {
case 'admin/help#documentation':
return t('The documentation module provides a framework for documenting all aspects of a Drupal installation');
case 'admin/config/system/documentation':
return t('The documentation module provides a framework for documenting all aspects of a Drupal installation');
case 'admin/documentation/module/%':
return t('The documentation module provides a framework for documenting all aspects of a Drupal installation');
}
}
/**
* Implements hook_menu().
*/
function doc_menu() {
$access = array('view documentation');
$administer = array('administer documentation');
$items['admin/config/system/documentation'] = array(
'title' => 'Documentation',
'description' => "View the documentation for this site's implementation of Drupal.",
'page callback' => 'drupal_get_form',
'page arguments' => array('doc_admin_settings_form'),
'access arguments' => $administer,
'type' => MENU_NORMAL_ITEM,
'file' => 'doc.admin.inc',
);
$items['admin/settings/documentation'] = array(
'title' => 'Documentation',
'description' => "View the documentation for this site's implementation of Drupal.",
'page callback' => 'drupal_get_form',
'page arguments' => array('doc_documentation'),
'access arguments' => $access,
'file' => 'doc.admin.inc',
);
$items['admin/settings/documentation/view'] = array(
'title' => 'View Documentation',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['admin/settings/documentation/settings'] = array(
'title' => 'Change Documentation Module Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('customfilter_filter_add'),
'access arguments' => $administer,
'type' => MENU_LOCAL_TASK,
);
$items['admin/documentation/module/%'] = array(
'title' => 'Create Documentation for Module',
'page callback' => 'drupal_get_form',
'page arguments' => array('doc_module_create_documentation',3),
'access arguments' => $administer,
'type' => MENU_CALLBACK,
'file' => 'doc.admin.inc',
);
return $items;
}
/**
* Implements hook_theme().
*/
function doc_theme() {
return array_merge(drupal_common_theme(), array(
'doc_modules' => array(
'render element' => 'form',
'file' => 'doc.admin.inc',
),
));
}
/**
* Implements hook_form_alter(). Adds the documentation field to a variety of forms.
*/
function doc_form_alter(&$form, &$form_state, $form_id) {
global $doc_entities;
if(isset($form_id) && array_key_exists($form_id,$doc_entities) && $form['#submit'][0] != 'taxonomy_vocabulary_confirm_delete_submit' ) {
doc_generateFields($form,$form_id);
module_load_include('inc', 'doc', 'doc.admin');
array_unshift($form['#submit'],$doc_entities[$form_id]['#submit_handler']);
}
//Add documentation links to modules page
if($form_id==='system_modules' && !isset($form['confirm'])) {
foreach (element_children($form['modules']) as $package) {
$form['modules'][$package]['#header'][4]['colspan'] = 4;
foreach(element_children($form['modules'][$package]) as $key){
$module = &$form['modules'][$package][$key];
// Stick it into $module for easier accessing.
$module['links']['documentation'] = array(
'#type' => 'link',
'#title' => 'Write Documentation',
'#href' => "admin/documentation/module/$key",
'#options' => array (
'attributes' => array(
'class' => array(
'module-link',
'module-link-documentation',
),
),
),
);
}
}
}
// dsm($form_id);
// dsm(print_r($form,true));
// dsm(get_defined_vars());
}
/**
* This function modifies the modules page to load in using a custom function, for the purpose of adding the Write Documentation links
*/
function doc_theme_registry_alter(&$theme_registry) {
if (!empty($theme_registry['system_modules_fieldset'])) {
$doc_theme_path = drupal_get_path('module', 'doc');
$doc_theme_file = 'doc.admin.inc';
$theme_registry['system_modules_fieldset']['file'] = 'doc_theme_file';
$theme_registry['system_modules_fieldset']['theme path'] = $doc_theme_path;
$theme_registry['system_modules_fieldset']['function'] = 'doc_theme_system_modules_fieldset';
$theme_registry['system_modules_fieldset']['includes'][0] = $doc_theme_path.'/'.$doc_theme_file;
}
}
/**
* This function generates the documentation field
*/
function doc_generateFields(&$form,&$form_id) {
global $doc_entities;
$id = doc_convertArrayToKeys($doc_entities[$form_id]['#id'],$form);
$entity = $doc_entities[$form_id]['#entity'];
$fieldset = doc_isset($doc_entities[$form_id],'#fieldset');
$doc_field = array(
'#type' => 'fieldset',
'#title' => 'Documentation',
'#collapsible' => true,
'#group' => $fieldset,
'documentation' => array(
'#title' => 'Create Documentation',
'#type' => 'textarea',
'#description' => t('Provide documentation for this @entity.',array('@entity' => $entity)),
'#default_value' => variable_get("doc_{$entity}_{$id}"),
),
);
$form['doc']['fieldset'] = $doc_field;
}
/**
* This is a convenience function that replaces PHP's native isset
*/
function doc_isset($var,$index=false,$default_value='') {
$return_value = (isset($var) ? $var : $default_value);
if($index){
$return_value = (isset($var[$index]) ? $var[$index] : $default_value);
}
return $return_value;
}
/**
* This is a convenience function that allows for array key paths to be encoded in another array
*/
function doc_convertArrayToKeys($keys,$arrayToAccess){
if(is_string($keys)){
return $keys;
} elseif(is_array($keys)){
if(count($keys) > 1)
if(isset($arrayToAccess[$keys[0]])){
return doc_convertArrayToKeys(array_slice($keys, 1), $arrayToAccess[$keys[0]]);
} else
return '';
else
// dsm($arrayToAccess);
return $arrayToAccess[$keys[0]];
}
}