View source
<?php
function menu_token_form_alter($form_id, &$form) {
if ($form_id == 'menu_edit_item_form') {
$path_field = $form['path'];
$form['path'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
);
$form['path']['path'] = $path_field;
$token_enabled = variable_get('menu_token_enabled', array());
$form['path']['token_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Use tokens in @path', array(
'@path' => t('Path'),
)),
'#description' => theme('token_help', 'menu_token'),
'#default_value' => isset($token_enabled[$form['mid']['#value']]),
);
$form_submit = array();
foreach ($form['#submit'] as $function => $params) {
$function = $function == 'menu_edit_item_form_submit' ? 'menu_token_edit_item_form_submit' : $function;
$form_submit[$function] = $params;
unset($function);
unset($params);
}
$form['#submit'] =& $form_submit;
}
elseif ($form_id == 'menu_item_delete_form') {
$form['#submit']['menu_token_item_delete_form_submit'] = array();
}
}
function menu_token_edit_item_form_submit($form_id, $form_values) {
$form_values['mid'] = menu_edit_item_save($form_values);
$token_enabled = variable_get('menu_token_enabled', array());
if (isset($form_values['token_enabled']) ? $form_values['token_enabled'] : FALSE) {
$token_enabled[$form_values['mid']] = $form_values['path'];
}
else {
unset($token_enabled[$form_values['mid']]);
}
variable_set('menu_token_enabled', $token_enabled);
return 'admin/build/menu';
}
function menu_token_item_delete_form_submit($form_id, $form_values) {
$token_enabled = variable_get('menu_token_enabled', array());
if (isset($token_enabled[$form_values['mid']])) {
unset($token_enabled[$form_values['mid']]);
}
variable_set('menu_token_enabled', $token_enabled);
}
function menu_token_footer() {
menu_token_replace();
}
function menu_token_menu($may_cache) {
menu_token_replace();
return array();
}
function menu_token_replace() {
global $_menu;
$token_enabled = variable_get('menu_token_enabled', array());
foreach ($token_enabled as $mid => $path) {
$_menu['items'][$mid]['path'] = token_replace_multiple($path);
menu_get_item($mid, NULL, TRUE);
}
}