Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

how user_hook() will change from drupal 6 to drupal 7

Parent Feed: 

Hooks is the central mechanism which allows Drupal its extensibility. New functionality can interact with or extend existing functionality using hooks. Use hook, don't hack is a standard way to write code in Drupal.

user_hook() is a hook which is called when an activity is performed on the user. e.g. A user logs in, logs out, clicks on user profile, etc.. 

In Drupal 6, user_hook is a single hook and there are operations accessible through $op for accessing the operation that was performed. The documentation is available here.

But in Drupal 7, this will change. The $op is gone and there are different hooks, depending on what operation is performed. List of available hooks are here.

There might be different repercussions of this:

First the big switch will not be required, making the code simpler from it is in Drupal 6

However, with one hook a dsm could always print which operations are called for a given operation. That will be harder to track now. A developer would need to implement different hook to figure out which ones get called on certain user related activities. It will be interesting to see what coding pattern emerges.

However, the documentation is very good and its intuitive to know which hook should be called, but still sometimes it can be hard to tell without a generic method.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web