I am trying to create a login link in Drupal 7 that will
keep the destination if set
generate a destination based on the page on which the link was clicked if not set
persist if set on subsequent clicks of the login link
not be generated if not already set AND the currently viewed page is an undesirable destination (such as user/logout)
I have written the following code and put it into to the body of a block only shown to anonymous users, however, as I am new to Drupal's api can someone more knowledgable here check to see if this is OK or can be optimized, and/or what other destinations other than user/* should NOT generate a destination if the destination is not already set:
<a href="/user<?php $curpath = current_path();
if (strpos($curpath, 'user/') === 0 && !isset($_GET['destination'])) {
print '';
}
else {
$newdest = drupal_get_destination();
$newdestimplode = implode('', $newdest);
print '?destination=' . drupal_get_path_alias($newdestimplode);
} ?>">Login</a>
Alternatively if you know of a setting that puts the login link on pages for anonymous users with the above conditions or a LIGHTWEIGHT module (please don't suggest LoginTobboggan) that does this, let me know here.