no need to check dependencies in hook_init

joachim - October 13, 2009 - 13:00
Project:Link Image Field
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

There is absolutely no need for all this sort of code in the module's hook_init:

function linkimagefield_init() {
// If Content, FileField, or ImageField is not available, immediately disable Link Image Field.
$disable = FALSE;
$message = '';

if (!module_exists('content')) {
$disable = TRUE;
$message = t('The Content Creation Kit needs to be installed for it to work properly.');
}

The .info file's dependencies list guarantees that this module will not be enabled without the required modules.

#1

johnfyoung - October 13, 2009 - 17:21

Joachim -
Question: what does Drupal do if those dependencies are disabled or uninstalled while linkimagefield is still enabled?

Does drupal fail gracefully or does it throw up the white screen of death?

#2

joachim - October 13, 2009 - 17:37

The module admin page won't let that happen; nor will drush.
If a system admin goes changing the system table by hand, then it's their problem, and it's not up to modules to account for that.

#3

hefox - November 3, 2009 - 02:11

First thing I thought when viewing the .module.

Patch attached, the include modeled after how filefield includes it's filefield_widget.inc

AttachmentSize
linkimagefield_no_init.patch 1.65 KB
 
 

Drupal is a registered trademark of Dries Buytaert.