function menu_target_preprocess_page in Menu target 7
Same name and namespace in other branches
- 8 menu_target.module \menu_target_preprocess_page()
Implements hook_preprocess_page().
File
- ./
menu_target.module, line 31 - Allows content editors to choose wether or not to open menu items in a new window
Code
function menu_target_preprocess_page(&$variables) {
// Only attach the javascript behavior when needed.
if (variable_get('menu_target_enabled', 1) && variable_get('menu_target_type', 'html') == 'javascript') {
drupal_add_js(drupal_get_path('module', 'menu_target') . '/menu_target.js');
}
foreach (array(
'main_menu',
'secondary_menu',
) as $name) {
if (isset($variables[$name])) {
foreach ($variables[$name] as $mlid_name => &$link) {
$mlid = str_replace('menu-', '', $mlid_name);
if (_menu_target_retarget_link($mlid)) {
$targeting = variable_get('menu_target_type', 'html');
// What kind of attributes depend on the settings
if ($targeting == 'html') {
$link['attributes']['target'] = "_blank";
}
else {
$link['attributes']['class'][] = "target-blank";
}
}
}
}
}
}