Skip to main content
1 of 5
krisbulman
  • 239
  • 4
  • 11

How to modify the login block markup?

I'm not all that used to modifying form output, and my searches have been unfruitful for this particular task.

GOAL: To swap the locations of the "Create new account"/"Forgot your password?" links with the submit button.

https://skitch.com/krisbulman/echee/welcome-to-d7.kgbdev.local-d7.kgbdev.local

As far as I've got:

I am able to modify certain contents of the login block by using this function:

function THEMENAME_form_user_login_block_alter(&$form, &$form_state){
  $item = array();
  $items[] = l(t('Create a new account'), 'user/register');
  $items[] = l(t('Forgot Your Password?'), 'user/password');
  $form['links']['#markup'] = theme('item_list', array('items' => $items));
}

And this template does pick up the changes, but simply outputs the form in a $content variable. How do I modify the override the content variable and print each element as a variable to alter the markup?

block--user--login.tpl.php

<div id="user-login-top">
  <?php print render($title_prefix); ?>
  <?php if ($block->subject): ?>
    <h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2>
  <?php endif;?>
 <?php print render($title_suffix); ?>
</div>
<div id="user-login-block" class="block block-<?php print $block->module ?>">
  <div class="content"<?php print $content_attributes; ?>>
    <?php print $content ?>
  </div>
</div>
<div id="user-login-bottom" class="block-bottom"></div>

This example uses straight markup out of firebug and it does the job: http://www.wdtutorials.com/drupal7/drupal-7-how-to-customize-user-login-form but it seems there should be a cleaner way to print the markup using existing variables that already contain the markup.. and doesn't remove the "Create new account" option if the site registration is restricted.

krisbulman
  • 239
  • 4
  • 11