I know it seems like a far distance away and as much as you'd like to ignore it, Drupal 7 is coming and it will be awesome. Some ambitious developers have actually started with Drupal 7 version of their modules, but what if you just want to get a little head start? I'll show you a few ways that you can help prepare your Drupal 6 modules now to help make life easier when you full port to Drupal 7 later on. To see a list of all the current 6.x to 7.x module changes, view http://drupal.org/node/224333.
<?php
/**
* Implementation of hook_user().
* @todo Remove in Drupal 7.
*/
function mymodule_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'form':
case 'validate':
$func = 'mymodule_user_'. $op;
return $func($edit, $account, $category);
}
}
/**
* Implementation of hook_user_form().
*/
function mymodule_user_form(&$edit, &$account, $category = NULL) {
if ($category == 'account') {
$form['mymodule_setting'] = array(
'#type' => 'textfield',
'#title' => t('MyModule setting'),
'#default_value' => isset($edit['mymodule_setting']) ? $edit['mymodule_setting'] : '',
);
return $form;
}
}
/**
* Implementation of hook_user_validate().
*/
function mymodule_user_validate(&$edit, &$account, $category = NULL) {
if (isset($edit['mymodule_setting']) && $edit['mymodule_setting'] != 'foobar') {
form_set_error('mymodule_setting', t('MyModule settings is not foobar.'));
}
}
?><?php
D6 BEFORE: $query = db_query("SELECT nid FROM {node} WHERE nid > %d AND title = '%s'", 20, 'foobar');
D6 AFTER: $query = db_query("SELECT nid FROM {node} WHERE nid > %d AND title = '%s'", array(':nid' => 20, ':title' => 'foobar'));
D7: $query = db_query("SELECT nid FROM {node} WHERE nid > :nid AND title = :title", array(':nid' => 20, ':title' => 'foobar'));
?>name = MyModule
description = This is really your module, not my module.
...
files[] = mymodule.module
files[] = mymodule.admin.inc
files[] = mymodule.pages.inc
files[] = mymodule.install<?php
/**
* Adds a new mycolumn column to the mymodule table.
*/
function mymodule_update_6020() {
$ret = array();
db_add_field($ret, 'mymodule', 'mycolumn', array('type' => 'int', 'default' => 0));
return $ret;
}
?>//@todo This is something to do!) so you can easily find them later on. Little thing to look out for are functions that you needed to backport for PHP4 (Drupal 7 requires PHP 5.2), referer_uri(), time(), drupal_clone(), etc.Be sure to mark anything you've identified
If you have found any other ways to help being porting your Drupal 6 module, please add a comment and I'll add it to the list!
Added to drupalsightings.com
In the info file, is it necessary to include the views includes?
I would guess not, since the views api already has a hook for that.
Not sure if the Views API will change with Drupal 7. I would probably go ahead and list all your includes, even ones for views in your .info files. It couldn't hurt.
thanks for the information. I need to just update my themes now :)
Post new comment