/[drupal]/contributions/modules/devel_forminspect/devel_forminspect.module
ViewVC logotype

Contents of /contributions/modules/devel_forminspect/devel_forminspect.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Mon Jan 15 08:40:12 2007 UTC (2 years, 10 months ago) by heine
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
Changes since 1.1: +2 -0 lines
File MIME type: text/x-php
Add cvs id tags
1 <?php
2
3 // $Id$
4
5 function devel_forminspect_help($section) {
6 switch ($section) {
7 case 'admin/settings/forminspect':
8 return t('Enable Form inspect and optionally provide form ids that should be ignored. A user needs the <a href="@url">access devel information</a> permission to view form information.', array('@url' => url('admin/user/access', NULL, 'module-devel')));
9 }
10 }
11
12 function devel_forminspect_menu($may_cache) {
13 $items = array();
14 if ($may_cache) {
15 $items[] = array(
16 'path' => 'admin/settings/forminspect',
17 'title' => t('Form inspect'),
18 'callback' => 'drupal_get_form',
19 'callback arguments' => array('devel_forminspect_settings'),
20 'access' => user_access('administer site configuration'),
21 'type' => MENU_NORMAL_ITEM,
22 'description' => t('Ignore certain forms.'),
23 );
24 }
25 return $items;
26 }
27
28
29 function devel_forminspect_settings() {
30 $form['devel_forminspect_enabled'] = array(
31 '#type' => 'checkbox',
32 '#title' => t('Display form information'),
33 '#default_value' => variable_get('devel_forminspect_enabled', FALSE),
34 );
35 $form['devel_forminspect_ignore'] = array(
36 '#type' => 'textarea',
37 '#title' => t('Ignore forms with the following ids'),
38 '#description' => t('Enter one form id per line. The * character is a wildcard. Example form ids are <em>devel_forminspect_settings</em> for this settings form or <em>*_node_form</em> for every node submission form. '),
39 '#default_value' => variable_get('devel_forminspect_ignore', ''),
40 );
41 return system_settings_form($form);
42 }
43
44 function devel_forminspect_form_alter($form_id, &$form) {
45 static $regexp;
46 if (variable_get('devel_forminspect_enabled', FALSE)) {
47 if (!isset($regexp)) {
48 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/'), array('|', '.*'), preg_quote(variable_get('devel_forminspect_ignore', ''), '/')) .')$/';
49 }
50 if (user_access('access devel information') && variable_get('devel_forminspect_display_form_dump', TRUE) && !preg_match($regexp, $form_id)) {
51 drupal_add_css(drupal_get_path('module', 'devel_forminspect') .'/devel_forminspect.css');
52 devel_forminspect_store_message(theme('devel_form_dump', $form_id, dprint_r($form, TRUE)));
53
54 $form['#suffix'] .= '<br /><b>'. check_plain($form_id) .'</b><br />';
55 }
56 }
57 }
58
59 function devel_forminspect_store_message($msg = '') {
60 static $messages;
61 if ($msg) {
62 $messages .= $msg;
63 }
64 return $messages;
65 }
66
67 function devel_forminspect_exit($destination = NULL) {
68 $messages = devel_forminspect_store_message();
69 if ($messages) {
70 if (isset($destination)) {
71 if (user_access('access devel information') && variable_get('devel_redirect_page', 0)) {
72 print $messages;
73 return;
74 }
75 else {
76 return;
77 }
78 }
79 if (user_access('access devel information') && $messages = devel_forminspect_store_message()) {
80 print $messages;
81 }
82 }
83 }
84
85 function theme_devel_form_dump($form_id, $form_dump) {
86 static $zebra;
87 $zebra = ($zebra == 'odd') ? 'even' : 'odd';
88 return '<h2 class="devel-form-title">'. check_plain($form_id) .'</h2><div class="devel-form-dump devel-form-dump-'. $zebra .'">'. $form_dump .'</div>';
89 }

  ViewVC Help
Powered by ViewVC 1.1.2