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

Contents of /contributions/modules/jump/jump.module

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


Revision 1.1 - (show annotations) (download) (as text)
Tue May 20 23:04:46 2008 UTC (18 months, 1 week ago) by marcp
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/x-php
Initial check-in of the Jump module.
1 <?php
2 // $Id$
3
4 /**
5 * Get a quick-jump menu form that contains a dropdown and a go button.
6 *
7 * @param $id If it's an array, then these are the options for the
8 * select box. If it's numeric, then check the type to see what it
9 * means.
10 * @param $type If 'menu' then $id is the top level menu id from which
11 * the options will be derived. If 'taxo' then $id is the vocabulary
12 * id from which the terms will be derived.
13 */
14 function jump_quickly($id = 1, $type = 'menu') {
15 if (is_array($id)) {
16 $options = $id;
17 }
18 else {
19 $options = array();
20 if ($type == 'menu') {
21 jump_menu_get_menu_options($options, $id);
22 }
23 else if ($type = 'taxo') {
24 jump_menu_get_taxo_options($options, $id);
25 }
26 }
27
28 // Give each form on the page a unique id so we can handle multiple
29 // jump forms...
30 static $num_jump_forms = 0;
31 $num_jump_forms++;
32 return drupal_get_form('jump_quickly_form_'. $num_jump_forms, $options);
33 }
34
35 function jump_quickly_form($options) {
36 $form = array();
37 $form['#submit'] = array('jump_quickly_form_submit' => 1);
38 $form['#theme'] = 'jump_quickly_form';
39 $form['#attributes']['class'] = 'jump-quickly';
40 $form['jump_goto'] = array(
41 '#type' => 'select',
42 '#default_value' => '0',
43 '#options' => $options
44 );
45 $form['submit'] = array(
46 '#type' => 'submit',
47 '#value' => t('Go')
48 );
49
50 return $form;
51 }
52
53 function jump_quickly_form_submit($form_id, $form_values) {
54 if (!empty($form_values['jump_goto'])) {
55 drupal_goto($form_values['jump_goto']);
56 }
57 }
58
59 function theme_jump_quickly_form($form) {
60 $output = '<div class="container-inline">';
61 $output .= drupal_render($form['jump_goto']);
62 $output .= drupal_render($form['submit']);
63 $output .= '</div>';
64 $output .= drupal_render($form);
65 return $output;
66 }
67
68 function jump_menu_get_menu_options(&$options, $pid) {
69 $menu = menu_get_menu();
70
71 if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
72 foreach ($menu['visible'][$pid]['children'] as $mid) {
73 $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
74 $item = menu_item_link($mid, FALSE);
75 $options[$item['href']] = $item['title'];
76 jump_menu_get_menu_options($options, $mid);
77 }
78 }
79 }
80
81 function jump_menu_get_taxo_options(&$options, $vid) {
82 $tree = taxonomy_get_tree($vid);
83 foreach ($tree as $term) {
84 $options[taxonomy_term_path($term)] = $term->name;
85 }
86 }
87
88 /**
89 * Return the first level of menu items underneath
90 * the given pid as a list...
91 */
92 function jump_menu_item_list($pid = 1) {
93 $output = '<ul>';
94 $menu = menu_get_menu();
95
96 if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
97 foreach ($menu['visible'][$pid]['children'] as $mid) {
98 $item = menu_item_link($mid);
99 $output .= '<li>'. $item ." [$mid]". '</li>';
100 }
101 }
102
103 $output .= '</ul>';
104 return $output;
105 }
106
107 /**
108 * Implementation of hook_forms() - allows us to use the same
109 * callbacks for forms with different ids.
110 */
111 function jump_forms() {
112 // Get the form id
113 $args = func_get_args();
114 $form_id = $args[0][0];
115
116 // Ensure we map a callback for our form and not something else
117 $forms = array();
118 if (strpos($form_id, 'jump_quickly_form') === 0) {
119 // Let the forms API know where to get the form data corresponding
120 // to this form id.
121 $forms[$form_id] = array('callback' => 'jump_quickly_form');
122 }
123 return $forms;
124 }

  ViewVC Help
Powered by ViewVC 1.1.2