Call function from another module

freefontaine - July 8, 2008 - 20:04

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;
}
?>

I would also like to know

jamestamr - July 15, 2008 - 15:19

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

I think you could use

meadtj - July 15, 2008 - 19:25

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

If the module exists, you

aj045 - July 15, 2008 - 20:56

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.

I think the function must

dennishu - April 1, 2009 - 03:15

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

To call a module function

almaceria - May 22, 2009 - 14:09

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.

calling a function in a separate module

ac00perw - June 12, 2009 - 17:37

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.

Thanks a lot.

dennishu - September 18, 2009 - 06:15

Thanks a lot.

That function is in

mattyoung - June 12, 2009 - 18:01

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

<?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;

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

}
?>

.

grobemo - June 12, 2009 - 20:14

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.

 
 

Drupal is a registered trademark of Dries Buytaert.