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

Contents of /contributions/modules/advanced_menu/advanced_menu.module

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


Revision 1.2 - (show annotations) (download) (as text)
Sun Feb 25 18:12:56 2007 UTC (2 years, 8 months ago) by timcn
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.1: +1 -15 lines
File MIME type: text/x-php
Updated for Drupal 5
1 <?php
2 // $Id: advanced_menu.module,v 1.1 2006/04/13 20:04:59 timcn Exp $
3
4
5 /**
6 * Implementation of hook_form_alter().
7 */
8 function advanced_menu_form_alter($form_id, &$form) {
9 $item = menu_get_item($form['mid']['#value']);
10
11 if ($form_id == 'menu_edit_item_form') {
12 $form['submit']['#weight'] = 5;
13
14 $form['options'] = array(
15 '#title' => t('Advanced options'),
16 '#type' => 'fieldset',
17 '#collapsible' => true,
18 '#collapsed' => (($item['type'] & MENU_VISIBLE_IN_TREE) > 0) && (($item['type'] & MENU_VISIBLE_IN_BREADCRUMB) > 0) && (($item['type'] & MENU_VISIBLE_IF_HAS_CHILDREN) <= 0),
19 '#weight' => 1,
20 '#tree' => false,
21 );
22
23 // move the expanded option into the fieldset
24 $form['options']['expanded'] = $form['expanded'];
25 unset($form['expanded']);
26
27 $form['options']['tree'] = array(
28 '#type' => 'checkbox',
29 '#title' => t('Visible in tree views') . ((($item['type'] & MENU_VISIBLE_IN_TREE) <= 0) ? ' ' . t('(currently invisible)') : ''),
30 '#default_value' => TRUE,
31 '#description' => t('Defines whether the menu item should be visible in tree views. (Affects the enabled/disabled option directly)'),
32 );
33
34 $form['options']['breadcrumb'] = array(
35 '#type' => 'checkbox',
36 '#title' => t('Visible in breadcrumbs'),
37 '#default_value' => ($item['type'] & MENU_VISIBLE_IN_BREADCRUMB) > 0,
38 '#description' => t('Defines whether the menu item should be shown in breadcrumbs.'),
39 );
40
41 $form['options']['children'] = array(
42 '#type' => 'checkbox',
43 '#title' => t('Only visible if it has children'),
44 '#default_value' => ($item['type'] & MENU_VISIBLE_IF_HAS_CHILDREN) > 0,
45 '#description' => t('Defines whether the menu item should be visible if it doesn\'t have any children.'),
46 );
47
48 $form['#validate'] = array(
49 'advanced_menu_edit_item_form_validate' => array(),
50 );
51 }
52 }
53
54
55 /**
56 * Validate the additional fields and merge them into $edit['type']
57 */
58 function advanced_menu_edit_item_form_validate() {
59 $edit =& $GLOBALS['form_values'];
60
61
62 if ($edit['tree']) {
63 $edit['type'] |= MENU_VISIBLE_IN_TREE;
64 }
65 else {
66 $edit['type'] &= ~MENU_VISIBLE_IN_TREE;
67 }
68
69 if ($edit['breadcrumb']) {
70 $edit['type'] |= MENU_VISIBLE_IN_BREADCRUMB;
71 }
72 else {
73 $edit['type'] &= ~MENU_VISIBLE_IN_BREADCRUMB;
74 }
75
76 if ($edit['children']) {
77 $edit['type'] |= MENU_VISIBLE_IF_HAS_CHILDREN;
78 }
79 else {
80 $edit['type'] &= ~MENU_VISIBLE_IF_HAS_CHILDREN;
81 }
82
83 return $edit;
84 }

  ViewVC Help
Powered by ViewVC 1.1.2