1

I have a module for my Drupal 7.x installation which needs browscap.ini / get_browser().

The module works perfectly, but I want to make sure the browscap.ini is installed before installing of enabling the module. That way the module will not work unless browscap is installed correctly.

How can I do this?

4
  • What is the name of the module that needs it? – 4life Sep 30 '13 at 10:59
  • Name of the module is: aserv_support. It's a self made module. I know it needs to be in the .install file, but I have no idea how. – Extigo Sep 30 '13 at 11:05
  • Please post some code so we can debug better – Scott Joudry Sep 30 '13 at 13:28
  • Maybe I'm not understanding, but why don't you just declare a dependency on whichever module (browsecap) you need? – Letharion Oct 1 '13 at 12:54
1

I fixed it using the following code:

/**
 * Implementation of hook_requirements().
 *
 */
function aserv_support_requirements($phase) {
  $requirements = [];

  if ($phase == 'install' || $phase == 'runtime') {

    if (!get_cfg_var('browscap')) {
      $requirements['aserv_support'] = [
        'title'    => t('Browscap not installed'),
        'value'    => 'Browscap has not be installed. Please install Browscap before enabling this module.',
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }

  return $requirements;
}

/**
 *  Implementation of hook_enable()
 */
function aserv_support_enable() {
  if (!get_cfg_var('browscap')) {
    drupal_set_message(t('ERROR Enabling Aserv_Support: Browscap has not be installed. Please install Browscap before enabling this module.'), 'error');
    module_disable(['aserv_support']);
  }
}
1
  • 1
    You should keep in mind that there is a browscap drupal module, requiring a PHP module only when there is also a standard PHP version isn't a good idea. It would be better to require either one. – Steven Oct 1 '13 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.