| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: admin.admin.inc,v 1.1.2.3 2009/06/15 04:31:31 yhahn Exp $ 3 4 /** 5 * Implementation of hook_form_alter() for menu_edit_item. 6 */ 7 function admin_form_menu_edit_item_alter(&$form, &$form_state) { 8 // If we are editing an item that is part of the admin menu, make 9 // adjustments so we provide ways of editing the items' options array. 10 if (!empty($form['menu']['original_item']['#value']['menu_name']) && $form['menu']['original_item']['#value']['menu_name'] == 'admin') { 11 if (!empty($form['menu']['options']['#value']) && is_array($form['menu']['options']['#value'])) { 12 foreach ($form['menu']['options']['#value'] as $k => $v) { 13 $form['menu']['options'][$k] = array( 14 '#type' => 'value', 15 '#value' => $v, 16 ); 17 } 18 } 19 unset($form['menu']['options']['#type']); 20 unset($form['menu']['options']['#value']); 21 $form['menu']['options']['#tree'] = TRUE; 22 $form['menu']['options']['#weight'] = 1; 23 24 $form['menu']['options']['admin']['#type'] = 'checkbox'; 25 $form['menu']['options']['admin']['#title'] = t('Display in admin menu'); 26 $form['menu']['options']['admin']['#description'] = t('If selected, this item will be displayed in the admin menu at the top of each page.'); 27 $form['menu']['options']['admin']['#default_value'] = $form['menu']['options']['admin']['#value']; 28 unset($form['menu']['options']['admin']['#value']); 29 } 30 } 31 32 /** 33 * Implementation of hook_form_alter() for menu_overview_form. 34 */ 35 function admin_form_menu_overview_form_alter(&$form, &$form_state) { 36 if ($form['#menu']['menu_name'] == 'admin') { 37 foreach (element_children($form) as $key) { 38 if (!empty($form[$key]['#item'])) { 39 $form[$key]['admin'] = array( 40 '#type' => 'checkbox', 41 '#default_value' => !empty($form[$key]['#item']['options']['admin']), 42 ); 43 } 44 } 45 $form['#theme'] = 'admin_menu_overview_form'; 46 $form['#submit'] = array('admin_menu_overview_form_submit'); 47 } 48 } 49 50 /** 51 * Theme the menu overview form into a table. 52 */ 53 function theme_admin_menu_overview_form($form) { 54 drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1); 55 drupal_add_tabledrag('menu-overview', 'order', 'sibling', 'menu-weight'); 56 57 $header = array( 58 t('Menu item'), 59 array('data' => t('Admin'), 'class' => 'checkbox'), 60 array('data' => t('Enabled'), 'class' => 'checkbox'), 61 array('data' => t('Expanded'), 'class' => 'checkbox'), 62 t('Weight'), 63 array('data' => t('Operations'), 'colspan' => '3'), 64 ); 65 66 $rows = array(); 67 foreach (element_children($form) as $mlid) { 68 if (isset($form[$mlid]['hidden'])) { 69 $element = &$form[$mlid]; 70 // Build a list of operations. 71 $operations = array(); 72 foreach (element_children($element['operations']) as $op) { 73 $operations[] = drupal_render($element['operations'][$op]); 74 } 75 while (count($operations) < 2) { 76 $operations[] = ''; 77 } 78 79 // Add special classes to be used for tabledrag.js. 80 $element['plid']['#attributes']['class'] = 'menu-plid'; 81 $element['mlid']['#attributes']['class'] = 'menu-mlid'; 82 $element['weight']['#attributes']['class'] = 'menu-weight'; 83 84 // Change the parent field to a hidden. This allows any value but hides the field. 85 $element['plid']['#type'] = 'hidden'; 86 87 $row = array(); 88 $row[] = theme('indentation', $element['#item']['depth'] - 1) . drupal_render($element['title']); 89 $row[] = array('data' => drupal_render($element['admin']), 'class' => 'checkbox'); 90 $row[] = array('data' => drupal_render($element['hidden']), 'class' => 'checkbox'); 91 $row[] = array('data' => drupal_render($element['expanded']), 'class' => 'checkbox'); 92 $row[] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']); 93 $row = array_merge($row, $operations); 94 95 $row = array_merge(array('data' => $row), $element['#attributes']); 96 $row['class'] = !empty($row['class']) ? $row['class'] .' draggable' : 'draggable'; 97 $rows[] = $row; 98 } 99 } 100 $output = ''; 101 if ($rows) { 102 $output .= theme('table', $header, $rows, array('id' => 'menu-overview')); 103 } 104 $output .= drupal_render($form); 105 return $output; 106 } 107 108 /** 109 * Submit handler for the admin menu overview form. 110 */ 111 function admin_menu_overview_form_submit($form, &$form_state) { 112 // When dealing with saving menu items, the order in which these items are 113 // saved is critical. If a changed child item is saved before its parent, 114 // the child item could be saved with an invalid path past its immediate 115 // parent. To prevent this, save items in the form in the same order they 116 // are sent by $_POST, ensuring parents are saved first, then their children. 117 // See http://drupal.org/node/181126#comment-632270 118 $order = array_flip(array_keys($form['#post'])); // Get the $_POST order. 119 $form = array_merge($order, $form); // Update our original form with the new order. 120 121 $updated_items = array(); 122 $fields = array('expanded', 'weight', 'plid'); 123 foreach (element_children($form) as $mlid) { 124 if (isset($form[$mlid]['#item'])) { 125 $element = $form[$mlid]; 126 // Update any fields that have changed in this menu item. 127 foreach ($fields as $field) { 128 if ($element[$field]['#value'] != $element[$field]['#default_value']) { 129 $element['#item'][$field] = $element[$field]['#value']; 130 $updated_items[$mlid] = $element['#item']; 131 } 132 } 133 // Hidden is a special case, the value needs to be reversed. 134 if ($element['hidden']['#value'] != $element['hidden']['#default_value']) { 135 $element['#item']['hidden'] = !$element['hidden']['#value']; 136 $updated_items[$mlid] = $element['#item']; 137 } 138 // Admin is also a special case -- we need to set its flag in the options array. 139 if ($element['admin']['#value'] != $element['admin']['#default_value']) { 140 $element['#item']['options']['admin'] = $element['admin']['#value']; 141 $updated_items[$mlid] = $element['#item']; 142 } 143 } 144 } 145 146 // Save all our changed items to the database. 147 foreach ($updated_items as $item) { 148 $item['customized'] = 1; 149 menu_link_save($item); 150 } 151 } 152 153 /** 154 * Implementation of hook_form_alter() for system_admin_theme_settings. 155 */ 156 function admin_form_system_admin_theme_settings_alter(&$form) { 157 // Add in our admin theme ('slate') as an option 158 $form['admin_theme']['#options']['slate'] = t('Slate (formerly \'Admin\')'); 159 } 160 161 /** 162 * Implementation of hook_form_alter() for node_filter_form. 163 */ 164 function admin_form_node_admin_content_alter(&$form) { 165 // If the admin theme has been inited, do some additional work. 166 global $theme; 167 if ($theme == 'admin') { 168 unset($form['admin']['options']['#type']); 169 unset($form['admin']['options']['#prefix']); 170 unset($form['admin']['options']['#suffix']); 171 $form['admin']['options']['#theme'] = 'admin_manage_options'; 172 } 173 } 174 175 /** 176 * Implementation of hook_form_alter() for admin_account_form. 177 */ 178 function admin_form_user_admin_account_alter(&$form) { 179 // If the admin theme has been inited, do some additional work. 180 global $theme; 181 if ($theme == 'admin') { 182 unset($form['options']['#type']); 183 unset($form['options']['#prefix']); 184 unset($form['options']['#suffix']); 185 $form['options']['#theme'] = 'admin_manage_options'; 186 } 187 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |