Commit 49f3e3f8 authored by develCuy's avatar develCuy
Browse files

Initial commit of menu_token module. Provides tokens in menu items(links).

parents
; $Id$
name = Menu Token
description = "Provides tokens in menu items(links)."
dependencies = token
<?php
// $Id$
/**
* Implementation of hook_form_alter().
*/
function menu_token_form_alter($form_id, &$form) {
if ($form_id == 'menu_edit_item_form') {
// Move 'Path' field into a fieldset
$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']]),
);
// Let me handle values submitted by form
$form['#submit']['menu_token_edit_item_form_submit'] = array();
}
}
function menu_token_edit_item_form_submit($form_id, $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['enabled']]['mid']);
variable_set('menu_token_enabled', $token_enabled);
}
/**
* Implementation of hook_footer().
*/
function menu_token_footer() {
global $_menu;
$token_enabled = variable_get('menu_token_enabled', array());
// Override paths
foreach ($token_enabled as $mid => $path) {
$_menu['items'][$mid]['path'] = token_replace_multiple($path);
}
// Force drupal to refresh menu tree with tokenized version,
menu_get_item(115, NULL, TRUE);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment