The error is caused from the fact you are declaring that hook_block_view()
implementation as requiring two arguments, but the code invoking hook_block_view()
is passing a single argument. If you would not want to see that error, you should use this code.
function mymodule_subscribe_block_view($delta = '', $myvariable = 0) {
switch ($delta) {
case 'mymodule_test':
$block['subject'] = t('Test block');
if (user_access('access content')) {
// Pass data through theme function.
$block['content'] = $myvariable;
}
return $block;
}
}
Now, although that code would fix the error message you are seeing, it would not solve the fact mymodule_subscribe_block_view()
would always receive 0 as second argument, since Drupal doesn't know anything about that implementation needing a second argument.
The question really is: How do I pass a value I calculate in some other function to a hook I implement in my module?
I take you are interested in passing a dynamic value, or the hook_block_view()
implementation could easily use a literal value in its code (e.g. $myvariable = 42;
).
Leaving out the case of hook_block_view()
calling a function to get the dynamic value it needs, you could use drupal_static()
to share a value between two functions (also in the case one of those functions is a hook, or both are hooks).
Keep in mind that:
- If the value returned from
drupal_static()
is set from another hook, you need to be sure hook_block_view()
is invoked after that hook; differently, hook_block_view()
will always receive the default value (passed as second argument to drupal_static()
)
- If the value returned from
drupal_static()
is set from a function (that is not a hook), you could as well directly call that function from the hook