banner



How To Change User Profile In Drupal 7

I was recently tasked with theming a customized user login page in Drupal seven. I could not discover a whole lot of documentation for this so the get-go place I looked was in the core modules binder hoping to discover something similar user--login.tpl.php that I would be able to copy and put in my theme folder for an override. No such luck, I looked in /modules/user but zilch there I could utilise. Next I looked around drupal.org and found some vague references to doing this in scattered posts. This took me a several hours merely finally I pieced together code from a agglomeration of posts and came upward with a method that worked well for me.

A Custom Themed Drupal Login Page

The Code

You tin add this code to your theme's template.php file where "your_themename" is the machine proper name of your theme. Here we tell Drupal that nosotros want auser-login.tpl.php file in our theme binder.

                                  part                  your_themename_theme                  ()                  {                  $items                  =                  assortment                  ();                  // create custom user-login.tpl.php                  $items                  [                  'user_login'                  ]                  =                  assortment                  (                  'render chemical element'                  =>                  'form'                  ,                  'path'                  =>                  drupal_get_path                  (                  'theme'                  ,                  'your_themename'                  )                  .                  '/templates'                  ,                  'template'                  =>                  'user-login'                  ,                  'preprocess functions'                  =>                  array                  (                  'your_themename_preprocess_user_login'                  ),                  );                  return                  $items                  ;                  }                              

You can now create a user-login.tpl.php and put it in your theme folder or the theme's template folder if there is one. Annotation that there are no "double dashes" in this file name every bit is typically traditional with Drupal 7 template file names.

A Few Ways to Theme it.

A trivial way to theme our custom user login is to simply render all the fields at once in your newly created user-login.tpl.php file with this:

                                  <?php                  print                  drupal_render_children                  (                  $form                  )                  ?>                              

This is probably fine in some cases only I needed to have something more granular. For this, I impress out the individual variables at the top of myuser-login.tpl.php file to run into what's available for theming.

                                  <?php                  /* print the variables if needed to allow for   individual field theming or breaking them upward. */                  print                  '<pre>'                  ;                  print_r                  (                  $variables                  );                  print                  '</pre>'                  ;                  ?>                              

At present articulate your enshroud and reload /user/login and the variables should print out. You will meet a huge by and large undecipherable list of variables here. What we are looking for are the top level array items. These volition include:

                                  [                  proper noun                  ]                  =>                  Array                  [                  pass                  ]                  =>                  Array                  [                  form_build_id                  ]                  =>                  Array                  [                  form_id                  ]                  =>                  Array                  [                  deportment                  ]                  =>                  Array                              

Themable Output

I tin covert these into themable output every bit such:

                                  <?php                  /* split the username and password from the submit push    so we can put in links above */                  impress                  drupal_render                  (                  $course                  [                  'name'                  ]);                  print                  drupal_render                  (                  $grade                  [                  'laissez passer'                  ]);                  impress                  drupal_render                  (                  $course                  [                  'form_build_id'                  ]);                  print                  drupal_render                  (                  $form                  [                  'form_id'                  ]);                  impress                  drupal_render                  (                  $class                  [                  'actions'                  ]);                  ?>                              

Well, you tin can see where this is going, y'all can actually theme this page notwithstanding you want now that all the fields are separate. I too needed to add together an prototype to this page so I can practise that using the theme path for my epitome.

                                  <div                  class=                  "login-photo"                  >                  <img                  src=                  "                  <?php                  impress                  base_path                  ()                  .                  drupal_get_path                  (                  'theme'                  ,                  'your_themename'                  )                  .                  '/images/login-photo.jpg'                  ;                  ?>                  "                  alt=                  "Login"                  championship=                  "Login"                  width=                  '327'                  meridian=                  '221'                  />                  </div>                              

Again, be certain to changeyour_themename to the car proper name of your theme. I've attached the finished theme file below so to use if for Drupal seven, you lot simply need to add in your template.php code above and then theme it however you want. Notation, to achieve the screen capture above of my custom login page, I used a little module I created to remove the login tabs so I could have a more unproblematic and elegant look to the page. I was now able to print those links just in a higher place the login button.

Resource

  • Customizing and Overriding User Login page, Register, and Password Reset in Drupal vi and seven
  • Remove Login Tabs Module (Sandbox)

Tags

Source: https://www.dannyenglander.com/blog/customizing-user-login-page-drupal-7/

Posted by: sanchezalmle1941.blogspot.com

0 Response to "How To Change User Profile In Drupal 7"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel