2

Generally, implementations of hook_requirements() don't use any Drupal function, when they are invoked during installation. node_requirements() uses some Drupal functions for whatever phase it is invoked.

  $requirements = array();
  // Ensure translations don't break at install time
  $t = get_t();
  // Only show rebuild button if there are either 0, or 2 or more, rows
  // in the {node_access} table, or if there are modules that
  // implement hook_node_grants().
  $grant_count = db_query('SELECT COUNT(*) FROM {node_access}')->fetchField();
  if ($grant_count != 1 || count(module_implements('node_grants')) > 0) {
    $value = format_plural($grant_count, 'One permission in use', '@count permissions in use', array('@count' => $grant_count));
  }
  else {
    $value = $t('Disabled');
  }

Which Drupal functions can be called in hook_requirements('install')?

3
  • Isn't that going to be an extremely long list? It might be better to ask which functions can't be called without checking the phase – Clive Jun 30 '12 at 22:56
  • The answer doesn't necessarily need to list each single function; it could just be "You can call any function defined in bootstrap.inc." I don't need a complete list, which would be obsolete as soon as Drupal defines new functions, or moves a function from a file to another. – kiamlaluno Jun 30 '12 at 23:00
  • Gotcha. Interesting question by the way I'm hoping this gets answered – Clive Jul 1 '12 at 2:45
0

I've made severals tests and I found that depending on modules that you've installed or other things the list of available functions is quite different.

So, IMHO the best way to see which functions you can access at that moment its to list them with the PHP function get_defined_functions. Below it's the small code that I used to list all the functions you can use.

<?php
if ($phase == 'install') {
  $funcs = get_defined_functions();
  file_put_contents('./functions.txt', var_export($funcs['user'], 1));
}
1
  • When I said Drupal functions, I was more interested on the functions Drupal defines in its includes/*.inc files; then I thought that some Drupal core modules could also be available too. I was not considering the difference between Drupal bootstrapped from Drush and Drupal bootstrapped because an administrative page being required, or any third-party modules. Probably I should at least consider Drupal being bootstrapped from Drush. – kiamlaluno Sep 18 '12 at 23:37

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.