Hi all,

I need to make some modificatons to my user login block.
- Translation of the text
- Add some extra links (html)
- Layout

I can add things with the block-user.tpl.php
But how can i do the translations and lay-out?

I don't want to use the 'locale' module.
I wan't the back-end to stay in english because all examples on the web are in english and i'm already used to that.

Thanks in advance

Robert

Comments

dsnoeck’s picture

I have used the hook_form_alter to change the link of Create a new account text.

In a custom module add:

function your_custom_module_name_form_alter(&$form, $form_state, $form_id) {
	if ($form_id == 'user_login_block') {
	  $items = array();
	  if (variable_get('user_register', 1)) {
	    $items[] = l(t('Create new account'), 'node/add/personalprofile', array('attributes' => array('title' => t('Create a new user account.'))));
	  }
	  $items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
	  $form['links']['#value'] = theme('item_list', $items);
       }
}

Don't forget to clear the cache to see your modification.

If you have other part of the form that you would like to change, copy the original code from http://api.drupal.org/api/function/user_login_block/6. In my example, I only have copied what I need.

Hope this will help you.
- Damien

- Damien
:: Keep Open Spirit ::

yoeld’s picture

Hello Damien,

I am trying to use your proposed approach. I am using the zen_classic theme. So I placed your code AS IS in my template.php of the theme with naming:

function zen_classic_form_alter(&$form, $form_state, $form_id)

I have cleared the cache, but nothing happens.

Could you point what am I missing?

Thanks, Yoel

nightowl77’s picture

I'm still trying to wrap my head around this as well, but I'm pretty sure you have to create a module and place the code above inside a module, for example call the module myCustomLogin which goes under sites/all/modules/myCustomLogin/myCustomLogin.module. You'll have to create an myCusomLogin.info as well for drupal to recognise the module.

Once you have enabled the module in the admin section, the code posted above will definitely change your login form.

That is of course very nice (that one module would make changes to the login form no matter what template your user use) but if you want to have a customized login that you place with the theme itself (ie not in the modules direcory) - I have no idea how to do that - still trying to figure that one out! :(

yoeld’s picture

Hi Richard,

Thanks ... that's was obvious, simply messed around!

For me, that is good enough. But if you want everything concentrated in your theme, have a look at this article:

http://thefaultandfracture.blogspot.com/2009/04/theming-drupal-user-logi...

Do you consider this more elegant than the module solution?

rowanprice’s picture

Here's how I did this for Drupal 7 within template.php (as in the theme file).

http://api.drupal.org/api/drupal/modules--user--user.module/function/use...

/**
 * Implements hook_form_FORM_ID_alter().
 */
function YOUR-THEME-NAME_form_user_login_block_alter(&$form) {
  $items = array();
  if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
    $items[] = l(t('Register'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'))));
  }
  $items[] = l(t('Forgot password'), 'user/password', array('attributes' => array('title' => t('If you forgot your password, click to request a new password via e-mail.'))));
  $form['links'] = array('#markup' => theme('item_list', array('items' => $items)));
}

p.s. in this same function, you can change the order of elements like this:

  $form['actions']['#weight'] = 5;
  $form['links']['#weight'] = 10;

-------------------------

For Google: Changing "Create new account" and "Forgot your password" in the user login block, in Drupal 7, by editing template.php

jienckebd’s picture

For Drupal 7

change
$form['links']['#value'] = theme('item_list', $items);

to
$form['links'] = array('#markup' => theme('item_list', array('items' => $items)));

eporama’s picture

I have just posted a solution to this for another group of people (in-house developers) and thought I'd share since it seems to be a fairly simple thing.

I don't know what you want to do with changing the layout, but this should help with the translations.

http://elementalmarkup.com/ramblings/theming-user-login-block

Hope it helps

eporama’s picture

Add the following to your settings.php

$conf['locale_custom_strings_en'] = array(
  'Request new password' => 'Forgot how to login?',
);

And that'll work for any basic text that is passed through the t() function.

See http://drupal.org/node/131061 for more technical information.

izmeez’s picture

subscribing. These are useful tips worth bookmarking. Thanks,

Izzy

dadderley’s picture

Thanks, This a very cool little feature that I have overlooked.