Hi , I am trying to create my own custom hook function to use in another modules. But it displays errors like “Warning: Missing argument 1 for access_hook_module_example_thingy() in access_hook_module_example_thingy() (line 17 of C:\wamp\www\Drupal\drupal_for_theme-7.22\sites\all\modules\access_hook_module\access_hook_module.module).”

What I did was,

1. I created module called hook_module.module. And then added below codes.

  $my_var = 'some_var';
  $data = module_invoke_all('example_thingy', $my_var);
  drupal_alter('example_thingy', $my_var);

2. Again I created a module called access_hook_module.module to access the custom hook “'example_thingy”. And then I added below codes.

  function access_hook_module_menu() {
	$items['hook_access'] = array(
		'title' => 'accessing hook module',
		'description' => ' Accessing the hook module example_thingy',
		'page callback' => 'access_hook_module_example_thingy',
		'access callback' => TRUE,
		'type' => MENU_NORMAL_ITEM,
	);
	return $items;
}

/**
 * Implements hook_example_thingy().
 */
function access_hook_module_example_thingy(&$my_var) {
	$my_var = 'foo';
  	return $my_var;
}

It displays errors. Anybody help me to fix this problem.

Comments

Jaypan’s picture

  $my_var = 'some_var';
  $data = module_invoke_all('example_thingy', $my_var);
  drupal_alter('example_thingy', $my_var);

Where?

It displays errors. Anybody help me to fix this problem.

What?

najubudeen’s picture

hi Jaypan, i try to create a custom hook function for other modules. i tried by using this website Creating custom hooks in Drupal and passing variables by reference. so i added below codes to define hook_name("example_thingy"). it is accessible in another modules by simply using MODULE_NAME_example_thingy().

Jaypan’s picture

I understand. But you didn't tell us where you put that code, or what the errors are, so we can't help with the information you've given.

najubudeen’s picture

i created a module called hook_module to define a hook_name function in it. and then i put these codes in it.


  $data = module_invoke_all( 'example_thingy' );

and then again i created a module called access_hook_module to test the created hook function outputs. so i added these codes below in it.

function access_hook_module_menu() {
    $items['hook_access'] = array(
        'title' => 'accessing hook module',
        'description' => ' Accessing the hook module example_thingy',
        'page callback' => 'access_hook_module_example_thingy',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );
    return $items;
}
/**
 * Implements hook_example_thingy().
 */
function access_hook_module_example_thingy(&$my_var) {
    $my_var = 'foo';
      return $my_var;
}

i want to pass variables by reference using access_hook_module_example_thingy(&$my_var) . when i run the above codes, it displays errors that Warning: Missing argument 1 for access_hook_module_example_thingy() in access_hook_module_example_thingy() (line 17 of C:\wamp\www\Drupal\drupal_for_theme-7.22\sites\all\modules\access_hook_module\access_hook_module.module).. how do i pass variables in "access_hook_module_example_thingy(&$my_var)" ?

Jaypan’s picture

function access_hook_module_menu()
{
  $items['hook_access'] = array(
    'title' => 'accessing hook',
    'description' => ' Accessing the hook module example_thingy',
    'page callback' => 'some_page',
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

function some_page()
{
  $my_var = 'hello';
  module_invoke_all( 'example_thingy', $my_var );

  return $my_var;
}

/**
* Implements hook_example_thingy().
*/
function access_hook_module_example_thingy(&$my_var)
{
  $my_var .= ' world';
}
najubudeen’s picture

hi, i tested your codes. It displays only hello. And then it displays errors like Warning: Missing argument 1 for access_hook_module_example_thingy() in access_hook_module_example_thingy() (line 23 of C:\wamp\www\Drupal\drupal_for_theme-7.22\sites\all\modules\access_hook_module\access_hook_module.module).
Notice: Undefined variable: my_var in access_hook_module_example_thingy() (line 24 of C:\wamp\www\Drupal\drupal_for_theme-7.22\sites\all\modules\access_hook_module\access_hook_module.module).
.

Jaypan’s picture

function some_page()
{
  $my_var = 'hello';

  $my_var = module_invoke_all('example_thingy', $my_var);

  return implode(' ', $my_var);
}

/**
* Implements hook_example_thingy().
*/
function access_hook_module_example_thingy($my_var)
{
  $my_var .= ' world';

  return $my_var;
}
najubudeen’s picture

hi jaypan, it works correctly now. thank you very much for your good help.