Frage

I've written a module that depends on an overridden value in $conf in settings.php. Specifically, it's a custom session handler set in $conf[session_inc]

This override needs to be present for the module to work and definitely needs to not be present when the module is disabled/uninstalled.

Is there anyway to stop the enable/disable process from within the .install file? I need to force users to configure settings.php properly before these actions. The return values of enable/disable hooks are apparently ignored.

I need to prevent users from sawing off the branch their sitting on :)

War es hilfreich?

Lösung

You can implement hook_requirements() to require the setting before the initial installation (install) and during status checks (runtime).

Preventing your module from being disabled doesn't seem possible within the .install file. Perhaps, instead, you can check for module_exists() in your session handler and route back to the default handler if your module is disabled?

Andere Tipps

Here is some example of preventing module to be enabled based on some variable from settings file:

/**
 * Implements requirements().
 */
function hook_devel_requirements($phase) {
  $requirements = array();
  // Ensure translations don't break at install time
  $t = get_t();

  if ($phase == 'install') {
    global $conf;
    if ($conf["my_environment"] == 'live') {
      $requirements['mymodule'] = array(
        'title' => $t('Custom Devel'),
        'value' => $t('This module should not be enabled on Production, sorry!'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

It's looking for global $conf['my_environment'] variable defined in settings file. And if it's set to 'live', it'll preventing the module to be enabled.

Remember to change hook and mymodule to your appropriate module name. The code should be used in .install file.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top