Return user to current page: How to link to a form from a Drupal menu
Press login / press account links for anonymous and logged in users, respectively. Subtly added to a bottom menu. Via code in order to allow for the redirect back to the page you were on after login or editing.
There is surely a way, or should be a way, that does not involve hook_page_alter(), but hey, this works.
<?php
/**
* Implements hook_page_alter().
*/
function feature_final_page_alter(&$page) {
if ($menu =& $page['footer']['menu_menu-utility']) {
if ($menu['378']['#attributes']['class'][0] == 'last') {
unset($menu['378']['#attributes']['class'][0]);
}
global $user;
if (!$user->uid) {
// If anonymous, set link and link title accordingly.
// Note: Path will be handed to l() and thus url().
$path = 'user';
$title = t('Press login');
$tooltip = t('Sign in or register for media-only access to high-resolution images and more.');
}
else {
// The user is logged in, direct them to their account page.
$path = 'user/' . $user->uid . '/edit';
$title = t('Press account');
$tooltip = t('Manage your contact information.');
}
$menu['feature_final_press'] = array(
'#theme' => 'menu_link__menu_utility',
'#attributes' => array(
'class' => array(
0 => 'last',
1 => 'leaf',
),
),
'#title' => $title,
'#href' => $path,
'#localized_options' => array(
'query' => drupal_get_destination(),
'attributes' => array(
'title' => $tooltip,
),
),
'#below' => array(),
);
}
}
?>
Comments
Post new comment