The following implementation of hook_requirements() depends on drupal_load(). When using a custom profile in a drupal installation, drupal_load() will always return false while the installer checks during the Verify requirements stage.

function formatted_number_requirements($phase) {
  if ($phase == 'install') {
    $requirements = array();
    // Ensure translations don't break at install time
    $t = get_t();
    drupal_load('module', 'format_number');
    if (!function_exists('format_number_get_options')) {
      $requirements['format_number'] = array(
        'title' => $t('Format Number API'),
        'description' => $t('%module-name requires, at least, version 6.x-1.1 of the <a href="@format-number">Format Number API</a> module.', array(
          '%module-name' => $t('Formatter Number CCK'),
          '@format-number' => 'http://drupal.org/project/format_number',
        )),
        'value' => $t('version 6.x-1.0'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    return $requirements;
  }
}

The problem is that drupal_load() is returning false during installation even if the requirement is present. A possible solution is to use runtime phase instead of install as the module dependency is already at the module's .info.

CommentFileSizeAuthor
#2 formatted_number.diff1.41 KBsilvio
formatted_number.diff13.72 KBsilvio

Comments

silvio’s picture

silvio’s picture

StatusFileSize
new1.41 KB

Sorry, corrected patch attached.

markus_petrux’s picture

Status: Active » Closed (won't fix)

The problem is that hook_requirements('runtime') does not cover the need to prevent the use of the module, so we'll get errors when code depending on the correct version of format_number is executed. What we want here is prevent the installation of this module if the correct version of format_number is not installed.

Why drupal_load() returns FALSE when invoked during the installation of a custom profile? That looks like a bug in Drupal (or the custom profile) to me.

markus_petrux’s picture

Title: hook_requirements() not working as expected during drupal installation » hook_requirements() not working as expected during drupal installation using custom profile