hachesilva
3/3/2013 - 1:19 AM

"De-Drupalizing The Login Form" correction Since the repository where Morten DK commited his code seems to be private, I decided to correct

"De-Drupalizing The Login Form" correction Since the repository where Morten DK commited his code seems to be private, I decided to correct the code from his article and give my own twist to it. I also added more fixes, like not being able to see the "Create new account" link if the site does not allow user registrations and fixing not only the page titles but the HTML titles appearing the browser window toolbar.

This code goes in your template.php file inside your MYTHEME folder.

This is the code used in my "seelva for Drupal" theme, http:github.com/seelva/seelva_drupal

<?php
/**
 * Implements hook_preprocess_HOOK().
 *
 */
function MYTHEME_preprocess_html(&$vars) {
  // Fixes page titles for login, register & password.
  switch (current_path()) {
    case 'user':
      $vars['head_title_array']['title'] = t('Login');
      $head_title = $vars['head_title_array'];
      $vars['head_title'] = implode(' | ', $head_title);
      break;
    case 'user/register':
      $vars['head_title_array']['title'] = t('Create new account');
      $head_title = $vars['head_title_array'];
      $vars['head_title'] = implode(' | ', $head_title);
      break;
    case 'user/password':
      $vars['head_title_array']['title'] = t('Request new password');
      $head_title = $vars['head_title_array'];
      $vars['head_title'] = implode(' | ', $head_title);
      break;

    default:
      break;
  }
}

/**
 * Implements hook_preprocess_HOOK().
 *
 */
function MYTHEME_preprocess_page(&$vars) {
  /**
  * Removes the tabs from user  login, register & password. Also fixes page titles
  */
  switch (current_path()) {
    case 'user':
      $vars['title'] = t('Login');
      unset($vars['tabs']['#primary']);
      break;
    case 'user/register':
      $vars['title'] = t('Create new account');
      unset($vars['tabs']['#primary']);
      break;
    case 'user/password':
      $vars['title'] = t('Request new password');
      unset($vars['tabs']['#primary']);
      break;

    default:
      break;
  }
}

/**
* Implements hook_form_FORM_ID_alter()
*
**/
function MYTHEME_form_user_login_alter(&$form, &$form_state, $form_id) {
  $actions_suffix = '<div class="actions-suffix">';
  $actions_suffix .= l(t('Request new password'), 'user/password', array('attributes' => array('class' => 'btn-login-password', 'title' => t('Get a new password'))));
  if (user_register_access()):
    $actions_suffix .= l(t('Create new account'), 'user/register', array('attributes' => array('class' => 'btn-login-register', 'title' => t('Create a new user account'))));
  endif;
  $actions_suffix .= '</div>';
  $form['actions']['#suffix'] = $actions_suffix;
}