1

I have the same function in two different modules to change the page: node/add.

I need the second one(see below) to override the first one. I implemented hook_install to change their weight but is not working. My guess is that the hook_install function is executed after those modules.

How can get this done?

Codes below:

My hook_install function

/**
* Implements hook_install().
*/
function utilities_install(){

db_update('system')
    ->fields(array('weight' => 10000))
    ->condition('name', '[content_type_thumbnail]', '=')
    ->execute();

}

Function in commerce_backoffice_product module:

 /**
 * Implements hook_theme_registry_alter().
 */
function commerce_backoffice_product_theme_registry_alter(&$theme_registry) {
  $theme_registry['node_add_list']['function'] = 'theme_commerce_backoffice_product_node_add_list';
}

/**
 * Override node_add_list theme.
 */
function theme_commerce_backoffice_product_node_add_list($variables) {
  $item = menu_get_item();

   .... code ....

  return theme_node_add_list($variables);
}

Function in content_type_thumbnail module

/**
 * Implements hook_theme_registry_alter().
 */
function content_type_thumbnail_theme_registry_alter(&$theme_registry) {
  $theme_registry['node_add_list']['function'] = 'content_type_thumbnail_node_add_list';
}

/**
 * Override of theme_node_add_list().
 */
function content_type_thumbnail_node_add_list($variables) {

  .... code ....

  return $output;
}
  • I´d like to know the reason of the down vote. This question is about function overlapping. It could be useful in other situations for other people. – chefnelone May 6 '13 at 11:18
  • Err did you un install and re install your module(s) after you changed the weight ? .install files will only be used while installing or updating. So if you had already installed it, weights will not change unless you re installed . – GoodSp33d May 6 '13 at 13:19
1

Rather than module weighting, I would suggest using hook_module_implements_alter to ensure your hook gets run last. So, something like this:

function hook_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'theme_registry_alter') {
    $group = $implementations['my_module'];
    unset($implementations['my_module']);
    $implementations['my_module'] = $group;
  }
}
| improve this answer | |
  • It worked. I didn't know that you can order the hooks executions. Thanks Alfred. – chefnelone May 8 '13 at 8:42
  • Yes, that piece of knowledge is something that needs to be spread more widely. – Alfred Armstrong May 8 '13 at 8:46

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.