Home Classroom Drupal An insight into the world of Drupal – Part 8

An insight into the world of Drupal – Part 8

1310

Part 8 – Moving from Drupal 5 to 6

As Drupal 6 becoming a solid platform and most of the contributed modules now supporting the new platform, one might need to migrate his older Drupal 5 site to 6. In this episode we would be looking at key changes in Drupal 6 that should be considered when adopting the new platform.

Schema API

In Drupal 6, a new Schema API has been introduced to allow modules to declare their database tables in a structured array replacing the need to write raw SQL queries in older versions. This schema structure is similar to how Form API operates and provides API functions for creating, dropping, and changing tables, columns, keys, and indexes. Further, this schema provides a convenient, DBMS independent system to define your tables.

With the introduction of Schema API, a new hook to integrate schema have been introduced as well. You can implement hook_schema in your module install script to use this new awesome improvement.

This is an example of how a simple Drupal schema definition will look like inside the hook_schema.

New Formats for hook_install and hook_uninstall

The format of hook_install has been changed to the following. Instead of writing SQL queries within your hook_install, just call drupal_install_schema() to invoke hook_schema and setup your tables.

In hook_uninstall use the following format.

New Syntax for .info Files for Modules

Now you can define your dependencies in your .info file in the module. Also, you can define the Drupal version compatible with your module as well as PHP compatibility.

name = Forum
description = Enables threaded discussions about general topics.
dependencies[] = taxonomy
dependencies[] = comment
core = 6.x
php = 5.1
Introduction of .info Files for Themes

Now you can define your regions simply inside your new .info file in the template directory. The format would be as follows.

name = mytheme
description = MyTheme description
version = VERSION
core = 6.x
engine = phptemplate
regions[left] = Left sidebar
regions[left_extra] = Left extra sidebar
regions[content] = Content
regions[content_extra] = Content Extra

Using Theme Registry

If you want to override a theme used in a hook through one of your templates, here is how you do it. Override hook_theme in your theme’s template.php file and follow the given format. Here search_form is the hook and mytemplate.tpl.php is the custom template that will be used to theme the output from the hook. For more complex overriding behaviours, study the hierarchy of Drupal theming system given in Figure 1.

Figure 1: Drupal theming hierarchy
(Source: About overriding themable output – http://drupal.org/node/173880)

Introduction of Preprocessor Functions

Preprocess functions applies only to theming hooks implemented as templates and the main role is to setup variables to be placed within the template (.tpl.php) files. This is a good attempt at removing the ugliness of _phptemplate_variables($hook, $vars) in older versions.

If you want to add/modify variables introduced through a hook named foo and if your theme is named ‘mytheme’ then you do the following.

Template Suggestions

Last but not least, the template suggestion system in Drupal 6 is worth a look at. For custom suggestions, you have to define your theme_preprocessor_page function in your theme and add template suggestions/variables that would be passed to the page template.

The following code will add template suggestions to the Drupal rendering system so that all the node renderings would look for a template named “page-node-{content_type}.tpl.php”

More, more and more!

This episode only touched the tip of the iceberg that is Drupal 6. For more information on changes from Drupal 5 to 6, check Drupal 6 theme guide (http://drupal.org/theme-guide/6) and Drupal 6 module migration guide (http://drupal.org/node/114774).

Comments

comments

Laknath Buddhika is an old Royalist and currently doing undergraduate studies at Faculty of IT, University of Moratuwa. He has worked on various fields of IT for more than a decade and is currently employed at Vesess Pvt Ltd for more than 2 years. He is an avid enthusiast of Open Source and has participated in Google Summer of code programme twice(2007,2008) representing Open Source organizations Gnome, Eclipse and also a member and a module contributor for Drupal community. He has a keen interest in the PHP language and PHP based CMSs such as Drupal, WordPress and Frameworks like CakePHP and CodeIgniter. He is also employed at DMS Pvt Ltd as a part-time PHP lecturer and wishes to spread PHP and the idea of Open Source throughout the Sri Lankan society.

NO COMMENTS

Leave a Reply