Wednesday, January 5, 2011

Changes for Drupal 7 Module developers

1.Permissions have titles (required) and descriptions (optional)

2.Permissions are no longer sorted alphabetically, but are displayed in the order defined in your hook_permission().

3._comment_load() is now comment_load()

4.Module .info files must now specify all loadable code files explicitly

5.The {permission} table is gone, instead we have a {role_permission} which stores (role ID, permission string) pairs. Thus, each permission granted for a given role ID is a separate row in the table.

6.The new default type for items in forms or other structured array data (e.g. node content) passed to drupal_render() is '#type' => 'markup'. In Drupal 6 and earlier, the HTML content was added to the array using the #value attribute. In Drupal 7, this needs to be changed to #markup.

7.Use defined constant REQUEST_TIME instead of time()

8.referer_uri() has been removed and replaced with the PHP-provided global variable $_SERVER['HTTP_REFERER'].

9.Use absolute path (constructed from DRUPAL_ROOT) when including a file
Drupal 6.x:
// Allow specifying special cache handlers in settings.php, like
// using memcached or files for storing cache information.
require_once variable_get('cache_inc', './includes/cache.inc');
?>

Drupal 7.x:
// Allow specifying special cache handlers in settings.php, like
// using memcached or files for storing cache information.
require_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc');
?>

10.drupal_uninstall_module() is now drupal_uninstall_modules()

11.drupal_set_title() uses check_plain() by default

12.New user_cancel API
Users with the "administer users" permission are able to override the default method, f.e. to completely delete a user including all of the related content.

13.When using variable_get to retrieve variables, the $default parameter now defaults to NULL, so if you're getting a variable where you don't care about what the default is, then you don't have to pass "NULL" as the second parameter.

14.Changed parameters for drupal_add_js() and drupal_add_css()
The drupal_add_js() and drupal_add_css() functions now take either a string defining the type of script that's being added to the page, or an array defining more about the data being added.

Drupal 6.x:
drupal_add_js('misc/collapse.js', 'module');
drupal_add_js('misc/collapse.js', 'module', 'footer');
drupal_add_js('misc/collapse.js', 'module', 'header', FALSE, TRUE, FALSE);
drupal_add_css('/modules/devel/devel.css', 'module');
drupal_add_css('/modules/devel/devel.css', 'module', 'screen');
drupal_add_css('/modules/devel/devel.css', 'module', 'all', FALSE);
?>

Drupal 7.x:
drupal_add_js('misc/collapse.js'); // 'module' must be removed or else css will not be added!
drupal_add_js('misc/collapse.js', array('type' => 'module', 'scope' => 'footer'));
drupal_add_js('misc/collapse.js', array('preprocess' => FALSE));
drupal_add_css('modules/devel/devel.css');
drupal_add_css('modules/devel/devel.css', array('media' => 'screen'));
drupal_add_css('modules/devel/devel.css', array('preprocess' => FALSE));
?>

15.Changed Drupal.behaviors to objects having the methods 'attach' and 'detach'
Drupal 6.x:
Drupal.behaviors.tableSelect = function(context) {
$('form table:has(th.select-all):not(.tableSelect-processed)', context).each(Drupal.tableSelect);
};

Drupal 7.x:
Drupal.behaviors.tableSelect = {
attach: function(context) {
$('form table:has(th.select-all):not(.tableSelect-processed)', context).each(Drupal.tableSelect);
}
};

16.Schema descriptions are no longer translated

17.Replace 'core', 'module' and 'theme' with 'file' in drupal_add_js()

Drupal 6.x:
drupal_add_js($jquery_plugin, 'core');
drupal_add_js($module_javascript, 'module');
drupal_add_js($theme_javascript, 'theme');
drupal_add_js($other_javascript, 'module');
drupal_add_js($file);
?>

Drupal 7.x:
drupal_add_js($jquery_plugin, array('weight' => JS_LIBRARY));
drupal_add_js($module_javascript, array('type' => 'file', 'weight' => JS_DEFAULT));
drupal_add_js($theme_javascript, array('weight' => JS_THEME));
drupal_add_js($other_javascript, 'file');
drupal_add_js($file);
?>

18.New hook_js_alter to alter JavaScript

Drupal 6.x:
function jquery_update_preprocess_page(&$variables) {
// Modify the scripts variable.
if (!empty($variables['scripts'])) {
?>

Drupal 7.x:
function jquery_update_js_alter(&$javascript) {
// Modify the JavaScript being presented on the page.
?>

19.The datetime field type has been removed in favour of database engine specific types

Drupal 6:
$schema['mymodule_table'] = array(
'description' => 'My table',
'fields' => array(
'id' => array(
'description' => 'The id',
'type' => 'serial'
),
'calendar_dt' => array(
'description' => 'Date field',
'type' => 'datetime',
'not null' => FALSE,
),
),
);
?>

Drupal 7:
$schema['mymodule_table'] = array(
'description' => 'My table',
'fields' => array(
'id' => array(
'description' => 'The id',
'type' => 'serial'
),
'calendar_dt' => array(
'description' => 'Date field',
'mysql_type' => 'DATETIME',
'pgsql_type' => 'timestamp without time zone',
'not null' => FALSE,
),
),
);
?>

20.theme_pager() no longer takes limit parameter
Drupal 6:
theme('pager', $tags, $limit, $element, $parameters, $quantity);
?>

Drupal 7:
theme('pager', array('tags' => $tags, 'element' => $element, 'parameters' => $parameters, 'quantity' => $quantity));
?>

21.Custom menu API
In Drupal 6 in order to create a custom menu (i.e. a menu you would create via admin/build/menu/add) you had to query the {menu_custom} table yourself.
In D7 several API functions to create, update and delete custom menus and related hooks were added.

function foo() {
$menu = array(
'title' => 'My menu',
'menu_name' => 'my_menu',
'description' => 'My custom menu',
);
// Add a new custom menu.
menu_save($menu);
// Delete the custom menu.
// Although only the 'menu_name' key is required, we pass the full
// $menu, so other modules may act on it.
menu_delete($menu);
}

function foo_menu_delete($menu) {
if ($menu['menu_name'] == 'my_menu') {
drupal_set_mesasge(t('You have deleted the foo custom menu.'));
}
}
?>

22.drupal_eval() renamed to php_eval

23.Changes to HTTP header functions
drupal_set_header() now takes the header name and header value as two separate arguments rather than as one complete header line, and has been renamed to drupal_add_http_header. The function now also supports appending to and removing existing headers.

24.Changes to HTTP header functions
drupal_set_header('Content-Type: text/plain');
?>

Drupal 7.x:
drupal_add_http_header('Content-Type', 'text/plain');
?>

Check this link for more information http://drupal.org/update/modules/6/7

No comments:

Post a Comment