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.

CommentFileSizeAuthor
#3 linkimagefield_no_init.patch1.65 KBhefox
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnfyoung’s picture

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?

joachim’s picture

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.

hefox’s picture

First thing I thought when viewing the .module.

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

mattcasey’s picture

+1 this patch to reduce module cruft

hefox’s picture

Status: Active » Needs review
pfrenssen’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.