I spent the better part of a work day trying to figure out how to render the user login block on the front page in Drupal 7, so I thought I would share some insight. In Drupal 6 I was able to display the block using the code
$block = (object) module_invoke('user', 'block', 'view', '0');
print theme('block',$block);
However, for whatever reason, this would not work in Drupal 7 and I couldn't find the delta index in block configuration. Therefore I sifted the forums until I found a solution using this code, also included are the styles etc.
<html>
<head>
<style type="text/css">
#container{
width:100%;
height:80%;
text-align:center;
padding-top:25px;
}
#login{
width:225px;
height:105px;
padding-top:10px;
padding-left:10px;
padding-right:10px;
margin-left:auto;
margin-right:auto;
margin-bottom:10px;
background-color:#D8D8BF;
border-color:black;
border-style:solid;
border-width:thin;
}
#edit-name{
}
#edit-pass{
}
.form-type-password{
margin-top:10px;
}
#edit-submit{
margin-top:15px;
float:right;
width:100px;
}
#head{
width:225px;
margin-left:auto;
margin-right:auto;
background-color:#660000;
text-align:center;
color:white;
padding:10px;
border-style:solid;
border-width:thin;
border-color:black;
}
</style>
</head>
<body>
<div id="container">
<div id="head">
<strong>Employee Login</strong>
</div>
<div id="login">
<?php
$elements = drupal_get_form('user_login_block');
$rendered = drupal_render($elements);
$output = '<form action="' . $elements['#action'] .
'" method="' . $elements['#method'] .
'" id="' . $elements['#id'] .
'" accept-charset="UTF-8"><div>';
$output .= $elements['name']['#children'];
$output .= $elements['pass']['#children'];
$output .= $elements['form_build_id']['#children'];
$output .= $elements['form_id']['#children'];
$output .= $elements['actions']['#children'];
$output .= '</div></form>';
print $output;
?>
</div>
If you experience problems logging in, please contact the help desk (Ext. 2329).
</div>
</body>
</html>This should create a tidy little login box for the front page for annonymous users. Other roles can be sent to a more fitting homepage. I also use the Login/Logout module to direct anyone who logs out back to the front page.
Comments
Comment #0.0
schnelle02 commentedincluded completed code
Comment #0.1
schnelle02 commentedadded code tags
Comment #1
timhilliard commentedtry setting the default front page to /user/login. Then set the authenticated user to the front page you want for everyone else. Does this make sense?
Comment #2
schnelle02 commentedYes, but I'm creating an intranet site and want them to see nothing but a login block center screen for employees to login. I didn't really have a question I posted how I did it for others to use.
Comment #3
timhilliard commentedThanks then for the info. I'll close this ticket to help keep the open issue queue lean.
Cheers,
Tim
Comment #4
makapacs commentedThank You schnelle02...it saved me day or maybe 3 days to figure this out.
Comment #4.0
makapacs commentedupdated