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

Contents of /contributions/modules/field_spotter/field_spotter.module

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


Revision 1.3 - (show annotations) (download) (as text)
Thu Jun 21 06:20:41 2007 UTC (2 years, 5 months ago) by unconed
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
File MIME type: text/x-php
Add user profile inspection for HEAD.
1 <?php
2
3 // Capture alter hooks of various types.
4 foreach (array(
5 'form' => array('a', 'form', 1),
6 // 'node' => array('object->content', 'node->content'), // not in core yet
7 'profile' => array('b->content', 'account->content', 2)
8 ) as $type => $array) {
9 list($var, $parent, $n) = $array;
10 $args = array();
11 for ($i = 0; $i < $n; ++$i) { $args[] = '&$'. chr(ord('a') + $i); }
12 eval("function field_spotter_{$type}_alter(". implode(', ', $args) .") { _field_spotter_alter('$type', '$parent', \$$var); }");
13 }
14
15 /**
16 * Alter everything hook for Form API-like structures.
17 */
18 function _field_spotter_alter($type, $parent, &$array) {
19 field_spotter_recurse($array, $parent);
20
21 drupal_add_js(drupal_get_path('module', 'field_spotter') .'/field_spotter.js');
22 drupal_add_css(drupal_get_path('module', 'field_spotter') .'/field_spotter.css');
23 }
24
25 /**
26 * Add wrappers to each element in the array recursively.
27 */
28 function field_spotter_recurse(&$array, $parent = '') {
29 static $ignore;
30 if (!isset($ignore)) {
31 $ignore = drupal_map_assoc(array('hidden'));
32 }
33 foreach (element_children($array) as $key) {
34 $item = &$array[$key];
35 if (isset($item['#type']) && isset($ignore[$item['#type']])) continue;
36 $id = $parent ? $parent .'[\''. addslashes($key) .'\']' : $key;
37 $prefix = '<span class="field-spotter" formkey="'. check_plain($id) .'">';
38 $suffix = '</span>';
39 $item['#prefix'] = isset($item['#prefix']) ? $prefix . $item['#prefix'] : $prefix;
40 $item['#suffix'] = isset($item['#suffix']) ? $item['#suffix'] . $suffix : $suffix;
41 field_spotter_recurse($item, $id);
42 }
43 }

  ViewVC Help
Powered by ViewVC 1.1.2