Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#3 | linkimagefield_no_init.patch | 1.65 KB | hefox |
Comments
Comment #1
johnfyoung CreditAttribution: johnfyoung commentedJoachim -
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?
Comment #2
joachim CreditAttribution: joachim commentedThe 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.
Comment #3
hefox CreditAttribution: hefox commentedFirst thing I thought when viewing the .module.
Patch attached, the include modeled after how filefield includes it's filefield_widget.inc
Comment #4
mattcasey CreditAttribution: mattcasey commented+1 this patch to reduce module cruft
Comment #5
hefox CreditAttribution: hefox commentedComment #6
pfrenssenLooks good.