Customizing and Overriding User Login page, Register, and Password Reset in Drupal 6 and 7

Customizing the user login, register, and password reset pages is fairly
simple, and uses the following concepts:

  • preprocessing to set variables

  • registration of functions in the theme registry

  • creation of one or more theme templates.

Step 1.
In the site theme directory, create or edit your
template.php file.

Step 2.
The first step is to implement hook_theme for
your theme. In the template.php file for your theme, look for a function
named yourtheme_theme() and modify it to add these return
values. If the function doesn‘t exist, add the following:

For D6:

<?php
/**
*
Registers overrides for various functions.
*
* In this case, overrides
three user functions
*/
function
yourtheme_theme() {
  return
array(
    ‘user_login‘ =>
array(
      ‘template‘
=>
‘user-login‘,
     
‘arguments‘ => array(‘form‘
=> NULL),
   
),
    ‘user_register‘ =>
array(
      ‘template‘
=>
‘user-register‘,
     
‘arguments‘ => array(‘form‘
=> NULL),
   
),
    ‘user_pass‘ =>
array(
      ‘template‘
=>
‘user-pass‘,
     
‘arguments‘ => array(‘form‘
=> NULL),
   
),
  );
}
?>

Notes about that code:

  • Change the function name by replacing "yourtheme" with the name of your
    theme

  • The template can be the same for all three. The example above uses a
    different template for each case: user-login, user-register, and
    user-pass

  • The template names must use a dash, not an underscore

  • Note:
    It‘s user_pass not user_password

For D7:

<?php
function
yourtheme_theme() {
  $items
= array();
 
$items[‘user_login‘] =
array(
    ‘render element‘ =>
‘form‘,
    ‘path‘
=>
drupal_get_path(‘theme‘,
‘yourtheme‘) .
‘/templates‘,
   
‘template‘ =>
‘user-login‘,
   
‘preprocess functions‘ =>
array(
      
‘yourtheme_preprocess_user_login‘
   
),
  );
 
$items[‘user_register_form‘]
= array(
    ‘render element‘ =>
‘form‘,
    ‘path‘
=>
drupal_get_path(‘theme‘,
‘yourtheme‘) .
‘/templates‘,
   
‘template‘ =>
‘user-register-form‘,
   
‘preprocess functions‘ =>
array(
     
‘yourtheme_preprocess_user_register_form‘
   
),
  );
 
$items[‘user_pass‘] =
array(
    ‘render element‘ =>
‘form‘,
    ‘path‘
=>
drupal_get_path(‘theme‘,
‘yourtheme‘) .
‘/templates‘,
   
‘template‘ =>
‘user-pass‘,
   
‘preprocess functions‘ =>
array(
     
‘yourtheme_preprocess_user_pass‘
   
),
  );
  return
$items;
}
?>

Notes about the D7 version:

  • The ‘path‘ lines tell Drupal where to find the .tpl.php files. This is
    optional, and in the code above, ‘path‘ tells Drupal to find the files in the
    templates subdirectory of the theme‘s base directory.

  • Note the "_form" added to the user_register element.

  • Note: As it is the case for D6,
    it‘s user_pass not user_password

Step 3.
Now you implement three preprocess functions.
There may be more concise ways to code this, but this works very well and is
easy to read, so here we go!

For D6:

<?php
function
yourtheme_preprocess_user_login(&$variables)
{
 
$variables[‘intro_text‘] =
t(‘This is my awesome login
form‘);
 
$variables[‘rendered‘] =
drupal_render($variables[‘form‘]);
}
function
yourtheme_preprocess_user_register(&$variables)
{
 
$variables[‘intro_text‘] =
t(‘This is my super awesome reg
form‘);
 
$variables[‘rendered‘] =
drupal_render($variables[‘form‘]);
}
function
yourtheme_preprocess_user_pass(&$variables)
{
 
$variables[‘intro_text‘] =
t(‘This is my super awesome insane
password form‘);
 
$variables[‘rendered‘] =
drupal_render($variables[‘form‘]);
}
?>

Notes about that code:

  • Change the function name by replacing "yourtheme" with the name of your
    theme

  • The line $variables[‘intro_text‘] adds the text
    that follows to the $variables array, which gets passed
    to the template as $intro_text

  • The second line renders the form and adds that code to
    the $variables array, which gets passed to the template
    as $rendered

For D7:
The code is even simpler for D7 because we don‘t need to
pass a variable containing the form content we want rendered. The variable
exists already in the $vars array and can be rendered in the .tpl.php file.

<?php
function
yourtheme_preprocess_user_login(&$vars)
{
 
$vars[‘intro_text‘] =
t(‘This is my awesome login
form‘);
}
function
yourtheme_preprocess_user_register_form(&$vars)
{
 
$vars[‘intro_text‘] =
t(‘This is my super awesome reg
form‘);
}
function
yourtheme_preprocess_user_pass(&$vars)
{
 
$vars[‘intro_text‘] =
t(‘This is my super awesome request new
password
form‘);
}
?>

The above preprocess functions simply add a variable into the $vars array
that is then displayed in the .tpl.php file. Much more complex manipulation of
the content of the render array is possible.

Please note, that the preprocess functions should go into the template.php
file.

Step 4.
Create template files to match
the ‘template‘ values defined above.

For D6
We need the following template files (make sure to use a
dash, not an underscore) :

  • user-login.tpl.php

  • user-register.tpl.php

  • user-pass.tpl.php

For D7
As for D6 but
with user-register-form.tpl.php for the register
form.

Step 5.
Paste the following into user-login.tpl.php.
Modify as necessary for user-register.tpl.php(D6)
and user-register-form.tpl.php (D7):

For D6:

<p><?php print
$intro_text;
?></p>
<div
class="my-form-wrapper">
  <?php print
$rendered;
?>
</div>

For D7:

<p><?php print
render($intro_text);
?></p>
<div
class="yourtheme-user-login-form-wrapper">
  <?php
print
drupal_render_children($form)
?>
</div>

Note the change to the syntax for causing Drupal to render the form. Also,
the D7 sample uses a different class for the div, but that‘s just a matter of
preference.

Step 6.
Save your template.php file to the theme‘s main
directory. Save your .tpl.php files in the same place for the D6 examples, or,
in the case of the D7 examples, to the directory you specify in the ‘path‘
element of the $items array.

Step 7.
Rebuild the cache. Go to Administration
> Performance
 and click on "Rebuild Cache" on the bottom of the
page.

Now, the user login page will contain the new text from the preprocess
function, and the tpl.php file(s) can be modified to suit the site‘s
needs.

Customizing and Overriding User Login page, Register, and
Password Reset in Drupal 6 and 7,布布扣,bubuko.com

Customizing and Overriding User Login page, Register, and
Password Reset in Drupal 6 and 7

时间: 2024-10-24 19:51:11

Customizing and Overriding User Login page, Register, and Password Reset in Drupal 6 and 7的相关文章

gitlab手残点错关闭注册No authentication methods configured on login page

Gitlab - 如何解決 "No authentication methods configured on login page" ? (gitlab version : 8.11.2) 转载 2016年12月19日 21:45:33 1572 1. 安裝 postgresql-client-common & postgresql-client $sudo apt-get install postgresql-client postgresql-client-common 2

google login page

<div class="container"> <div class="row"> <div class="col-sm-6 col-md-4 col-md-offset-4"> <h1 class="text-center login-title">Sign in to continue to Bootsnipp</h1> <div class="a

a simple machine learning system demo, for ML study.

Machine Learning System introduction This project is a full stack Django/React/Redux app that uses token based authentication with Knox. Then I add Machine Learning features for demostrate the full workflow of the data mining, including the four stag

struts2学习笔记之十八(国际化)

java国际化 程序国际化: 程序可以根据机器所在国家.语言环境,自动翻译内容 国际化的本质就是:查找.替换,从资源包里找到相应国家下的关键字对应的语言文字 国际化的步骤: (1)提供国际化资源文件 如果国家化资源包中有非西欧字符,需要使用native2ascii处理文件, native2ascii sourcefile destfile 生成一个是Unicode字符的文件 资源文件的写法:文件名语言代码国家代码 xiyang_en_US.properties hi="hello" x

Windows server 2008 R2 & Win 7 Password reset

For Windows server 2008 R2Password reset: (Usethe Microsoft Technology to decrypt the password) Prepare the WINPE ISO winpe3_amd64.iso WindowsPreinstallation Environment https://en.wikipedia.org/wiki/Windows_Preinstallation_Environment Howto Create a

&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Login.aspx.cs&quot; Inherits=&quot;Login&quot; %&gt;

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %> <%@ Page Language="C#" AutoEventWireup="true" Codebehing="Login.aspx.cs" Inherits=&qu

Customizing Site-Wide Behavior for ASP.NET Web Pages (Razor) Sites

By Tom FitzMacken|February 17, 2014 This article explains how to make site-side settings for pages in an ASP.NET Web Pages (Razor) website. What you'll learn: How to run code that lets you set values (global values or helper settings) for all pages i

[MODx] 6. Cache &#39;!&#39; with login package

1. Install login package. 2. Create a Template called 'login': [[!Login? &loginResourceId=`13` // means after login, redirect resource 13 page, in our case, redirect to self ]] <h2>Register</h2> [[!Register? &submitVar=`registerbtn` &a

Android+struts2+JSON方式的手机开发(Login)

在手机的后台服务无论是调用WebService还是Http请求,多数都是采用Android的HttpClient实现相关的调用实现.本文实现Android+Struts2+JSON方式实现为手机前台提供服务. 涉及的知识点: 1.Struts2框架的搭建(包括Struts2的jSON插件) 2.Android前台访问Web采用HttpClient方式. 3.Android采用JSON的解析. 功能:模拟远程登录流程: 手机后台服务:由于采用Struts2的JSON响应格式,响应详细会自动转变为J