2

I'm using LoginToboggan as my login page, and on the login form, it has: "You are not logged in." I want to be able to edit this text, and the admin interface doesn't give an option to do so.

Searching around, I see that this is set in the LoginToboggan module in a theme function:

function theme_lt_unified_login_page($variables) {
...
$output .= '<div id="login-message">' . t('You are not logged in.') . '</div>';
...
}

So I can't edit the module directly, nor would I wish to "patch" it. I see that theme_lt_unified_login_page is called by:

function logintoboggan_unified_login_form($active_form = 'login') {
...
$output = theme('lt_unified_login_page', $variables);
...
}

I don't really understand what hook I would use to intercept and override / edit just this text? It doesn't appear in the $form object.

1 Answer 1

6

The quickest way might be/would be to copy...

/**
 * Theme function for unified login page.
 *
 * @ingroup themable
 */
function theme_lt_unified_login_page($variables) {

  $login_form = $variables['login_form'];
  $register_form = $variables['register_form'];
  $active_form = $variables['active_form'];
  $output = '';

  $output .= '<div class="toboggan-unified ' . $active_form . '">';

  // Create the initial message and links that people can click on.
  $output .= '<div id="login-message">' . t('You are not logged in.') . '</div>';
  $output .= '<div id="login-links">';
  $output .= l(t('I have an account'), 'user/login', array('attributes' => array('class' => array('login-link'), 'id' => 'login-link')));
  $output .= ' ';
  $output .= l(t('I want to create an account'), 'user/register', array('attributes' => array('class' => array('login-link'), 'id' => 'register-link')));

  $output .= '</div>';

  // Add the login and registration forms in.
  $output .= '<div id="login-form">' . $login_form . '</div>';
  $output .= '<div id="register-form">' . $register_form . '</div>';

  $output .= '</div>';

  return $output;
}

to your theme's template.php file and rename it...

/**
 * Theme function for unified login page.
 *
 * @ingroup themable
 */
function YOURTHEME_lt_unified_login_page($variables) {

  $login_form = $variables['login_form'];
  $register_form = $variables['register_form'];
  $active_form = $variables['active_form'];
  $output = '';

  $output .= '<div class="toboggan-unified ' . $active_form . '">';

  // Create the initial message and links that people can click on.
  $output .= '<div id="login-message">' . t('PLACE YOUR CUSTOM MESSAGE HERE.') . '</div>';
  $output .= '<div id="login-links">';
  $output .= l(t('I have an account'), 'user/login', array('attributes' => array('class' => array('login-link'), 'id' => 'login-link')));
  $output .= ' ';
  $output .= l(t('I want to create an account'), 'user/register', array('attributes' => array('class' => array('login-link'), 'id' => 'register-link')));

  $output .= '</div>';

  // Add the login and registration forms in.
  $output .= '<div id="login-form">' . $login_form . '</div>';
  $output .= '<div id="register-form">' . $register_form . '</div>';

  $output .= '</div>';

  return $output;
}

...along with whatever you wanted that login-message to be. Clear caches/theme registry and you should be on your way.

ADDITION:

This drupal fu works because, instead of calling theme_lt_unified_login_page() directly, it does it like this:

$output = theme('lt_unified_login_page', $variables);

and it is the theme() function that does the magic in that when you build the theme registry, it will discover that there is a YOURTHEME_lt_unified_login_page() function out there, and will call that as an override to the theme_lt_unified_login_page() one that logintoboggan provides.

(Note that the first argument doesn't start with theme_ or YOURTHEME_, one of these are prepended by the theme system as described above.)

2
  • Interesting; although I'm a little confused how this works - I assumed that theme_lt_unified_login_page was a function unique to the logintoboggan module that would be called at some point in a hook - how does Drupal know that the replacement function in template.php should take the place of the one in logintoboggan.module?
    – njp
    Commented Jun 6, 2013 at 8:34
  • 1
    see additions to answer for some more information. drupal.org/documentation/theme is a good start as well for lots more info on drupal theming.
    – Jimajamma
    Commented Jun 6, 2013 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.