Archive for August, 2010

Drupal hook: hook_user

Drupal offers user management out of the box. This includes new user registration, log in, password mailer and user session management. Drupal stores password as md5 hash value. When a user provides her log in credentials, Drupal generates md5 has values for the password provided and compares it with the one stored in the database against the provided username/email address. This is a well known technique implemented by Unix.

Though Drupal manages the users, we can still alter the behavior of different default actions on a user activity. For example, if you log in from the front page, by default, you will be redirected to front page. Instead we can make to redirect to different page or different front page, that can only be accessed by logged users. To achieve this, we need to use hook_user Drupal hook.

Read moreĀ  Drupal hook: hook_user.

Drupal: Auto complete field

Drupal auto complete field lets you select values appear as you type in the text box. Which maximizes the usability and user experience.

Think of a situation, You are creating a custom search function which display author picture, some text containing the word(s) you are typing and node post date.

This can not be achieved by creating a CCK auto complete field since such fields can be added to node types only. You need to create a custom module and write hook_search (no more supported in Drupal 7.x). You have to define a extra attribute in your text box definition: #autocomplete_path. The value this attribute takes is a path defined with hook_menu known to your Drupal site. Any non-existing path assigned to this attribute will result in error. So, first make sure you have defined the path and the callback function with proper permissions.

The auto complete works on ‘change’ event of the text box. As you type, the path defined in #autocomplete_path calls the function defined in ‘callback function’ of the menu definition. The function may fetch values from the site database contact third party services.

The function should return an array with key-value pairs. The values matching with the text in the text box will be displayed under the text box and you can select any of the values using either mouse of up-down keys.

Read more: Drupal: Auto complete field.

Rss Feed Tweeter button Facebook button Technorati button Reddit button Myspace button Linkedin button Webonews button Delicious button Digg button Flickr button Stumbleupon button Newsvine button Youtube button