I'm trying to call the "contact_site_page()" found in the "contact" module function from another custom module. Basically, I want to add another path that displays the same form as www.somedomain.com/contact. I am trying to do this with "hook_menu_alter", is that right? It all works except when I assign "contact_site_page" to the "page_callback". Throws a "Call to undefined function" error. I really just want to know exactly how I can call functions from other modules. Can anyone help?

Here is what I have been trying:

<?php 
function myModule_menu_alter(&$callbacks) {
  // Example - disable the page at node/add
  //drupal_set_message('this alter function is being called');
  $callbacks['myNewURL']['title'] = "Next Steps";
  $callbacks['myNewURL']['page callback'] = 'contact_site_page';
  $callbacks['myNewURL']['access arguments'] = array('access site-wide contact form');
  $callbacks['myNewURL']['type'] = MENU_CALLBACK;
}
?>

Comments

jamestombs’s picture

I would also like to know this. Is it possible just to include the module file?

James T
Action Medical Research - www.action.org.uk

James T
Action Medical Research - www.action.org.uk

thomasmeadows’s picture

I think you could use drupal_goto('contacts'); I'm not certain though, I haven't used hook_menu_alter before.

http://api.drupal.org/api/function/drupal_goto/6

aj045’s picture

If the module exists, you should be able to just call the function. For example, taxonomy is a module in Drupal. Often I deal with modules that need to work with the taxonomy terms of a node. I usually just assume those functions from taxonomy exist when writing code.

dennishu’s picture

I think the function must also be in the .module file. If it's in a .inc file, it seems not to be callable.

almaceria’s picture

To call a module function defined in a file different from the .module file, you should load first the file using the module_load_include function (version 6.x-7).
After that you can call the function normally.

ac00perw’s picture

module_load_include('inc', 'feedburner', 'feedburner.admin');

Can be used to call functions that exist in a file called feedburner.admin.inc in the feedburner module as an example.

dennishu’s picture

Thanks a lot.

mattyoung’s picture

That function is in 'contact.pages.inc' which is not included automatically by drupal. You need to add two more keys to the menu:

function myModule_menu_alter(&$callbacks) {
  // Example - disable the page at node/add
  //drupal_set_message('this alter function is being called');
  $callbacks['myNewURL']['title'] = "Next Steps";
  $callbacks['myNewURL']['page callback'] = 'contact_site_page';
  $callbacks['myNewURL']['access arguments'] = array('access site-wide contact form');
  $callbacks['myNewURL']['type'] = MENU_CALLBACK;

  $callbacks['myNewURL']['file path'] = drupal_get_path('module', 'contact');
  $callbacks['myNewURL']['file'] = 'contact.page.inc';

}
grobemo’s picture

The most general answer to your question is: Use module_invoke. module_invoke('node','show',123), for instance, is like calling node_show(123).

For your more specific needs, you could try drupal_get_form. Specifically, try drupal_get_form('contact'). I don't know how this will work if the contact module hasn't been included yet, but you can give it a shot.

I haven't used hook_menu_alter, but based on the Drupal API page for it, it doesn't look like what you need. drupal_goto would work in some cases, as meadtj says, though it will actually redirect the user to yoursite.com/contact.