Community Documentation

module_invoke

5 module.inc module_invoke()
6 module.inc module_invoke()
7 module.inc module_invoke($module, $hook)
8 module.inc module_invoke($module, $hook)

Invoke a hook in a particular module.

Parameters

$module: The name of the module (without the .module extension).

$hook: The name of the hook to invoke.

...: Arguments to pass to the hook implementation.

Return value

The return value of the hook implementation.

Related topics

▾ 70 functions call module_invoke()

aggregator_admin_form in modules/aggregator/aggregator.admin.inc
Form constructor for the aggregator system settings.
aggregator_form_aggregator_admin_form_alter in modules/aggregator/aggregator.processor.inc
Implements hook_form_aggregator_admin_form_alter().
aggregator_refresh in modules/aggregator/aggregator.module
Checks a news feed for new items.
block_admin_configure in modules/block/block.admin.inc
Form constructor for the block configuration form.
block_admin_configure_submit in modules/block/block.admin.inc
Form submission handler for block_admin_configure().
block_form_user_profile_form_alter in modules/block/block.module
Implements hook_form_FORM_ID_alter() for user_profile_form().
bootstrap_invoke_all in includes/bootstrap.inc
Invokes a bootstrap hook in all bootstrap modules that implement it.
dashboard_page_build in modules/dashboard/dashboard.module
Implements hook_page_build().
drupal_check_module in includes/install.inc
Check a module's requirements.
drupal_cron_run in includes/common.inc
Executes a cron run when called.
drupal_get_complete_schema in includes/bootstrap.inc
Gets the whole database schema.
drupal_get_library in includes/common.inc
Retrieves information for a JavaScript/CSS library.
drupal_get_schema_unprocessed in includes/common.inc
Returns the unprocessed and unaltered version of a module's schema.
drupal_install_system in includes/install.inc
Callback to install the system module.
drupal_uninstall_modules in includes/install.inc
Uninstalls a given list of modules.
field_associate_fields in modules/field/field.module
Allows a module to update the database for fields and columns it controls.
field_attach_delete in modules/field/field.attach.inc
Delete field data for an existing entity. This deletes all revisions of field data for the entity.
field_attach_delete_revision in modules/field/field.attach.inc
Delete field data for a single revision of an existing entity. The passed entity must have a revision id attribute.
field_attach_insert in modules/field/field.attach.inc
Save field data for a new entity.
field_attach_load in modules/field/field.attach.inc
Loads fields for the current revisions of a group of entities.
field_attach_update in modules/field/field.attach.inc
Save field data for an existing entity.
field_create_field in modules/field/field.crud.inc
Creates a field.
field_delete_field in modules/field/field.crud.inc
Marks a field and its instances and data for deletion.
field_delete_instance in modules/field/field.crud.inc
Marks a field instance and its data for deletion.
field_purge_data in modules/field/field.crud.inc
Purges the field data for a single field on a single pseudo-entity.
field_purge_field in modules/field/field.crud.inc
Purges a field record from the database.
field_purge_instance in modules/field/field.crud.inc
Purges a field instance record from the database.
field_read_fields in modules/field/field.crud.inc
Reads in fields that match an array of conditions.
field_ui_display_overview_form in modules/field_ui/field_ui.admin.inc
Form constructor for the field display settings for a given view mode.
field_ui_field_edit_form in modules/field_ui/field_ui.admin.inc
Form constructor for the field instance settings form.
field_ui_field_settings_form in modules/field_ui/field_ui.admin.inc
Form constructor for the field settings edit page.
field_update_7001 in modules/field/field.install
Fix fields definitions created during the d6 to d7 upgrade path.
field_update_field in modules/field/field.crud.inc
Updates a field.
file_file_download in modules/file/file.module
Implements hook_file_download().
filter_get_filters in modules/filter/filter.module
Return a list of all filters provided by modules.
help_links_as_list in modules/help/help.admin.inc
Provides a formatted list of available help topics.
help_page in modules/help/help.admin.inc
Menu callback; prints a page listing general help for a module.
hook_search_execute in modules/search/search.api.php
Execute a search for a set of key words.
image_effect_definitions in modules/image/image.module
Pull in image effects exposed by modules implementing hook_image_effect_info().
image_styles in modules/image/image.module
Get an array of all styles and their settings.
module_disable in includes/module.inc
Disable a given set of modules.
module_enable in includes/module.inc
Enables or installs a given list of modules.
module_test_hook_dynamic_loading_invoke in modules/simpletest/tests/module_test.module
Page callback for 'hook dynamic loading' test.
node_filters in modules/node/node.admin.inc
List node administration filters that can be applied.
node_filter_form in modules/node/node.admin.inc
Return form for node administration filters.
node_search_execute in modules/node/node.module
Implements hook_search_execute().
path_admin_overview in modules/path/path.admin.inc
Return a listing of all defined URL aliases.
search_admin_settings in modules/search/search.admin.inc
Menu callback: displays the search module settings page.
search_cron in modules/search/search.module
Implements hook_cron().
search_data in modules/search/search.module
Performs a search by calling hook_search_execute().
search_invoke_preprocess in modules/search/search.module
Invokes hook_search_preprocess() in modules.
StatisticsReportsTestCase::testPopularContentBlock in modules/statistics/statistics.test
Tests the "popular content" block.
system_get_module_admin_tasks in modules/system/system.module
Generate a list of tasks offered by a specified module.
system_modules in modules/system/system.admin.inc
Menu callback; provides module enable/disable interface.
update_get_update_list in includes/update.inc
Return a list of all the pending database updates.
user_admin_permissions in modules/user/user.admin.inc
Menu callback: administer permissions.
user_modules_installed in modules/user/user.module
Implements hook_modules_installed().
user_permission_get_modules in modules/user/user.module
Determine the modules that permissions belong to.
watchdog in includes/bootstrap.inc
Logs a system message.
watchdog_skip_semaphore in modules/simpletest/tests/actions_loop_test.module
Replacement of the watchdog() function that eliminates the use of semaphores so that we can test the abortion of an action loop.
_block_rehash in modules/block/block.module
Updates the 'block' DB table with the blocks currently exported by modules.
_block_render_blocks in modules/block/block.module
Render the content and subject for a set of blocks.
_field_info_collate_types in modules/field/field.info.inc
Collates all information on field types, widget types and related structures.
_field_info_prepare_field in modules/field/field.info.inc
Prepares a field definition for the current run-time context.
_node_types_build in modules/node/node.module
Builds and returns the list of available node types.
_options_get_options in modules/field/modules/options/options.module
Collects the options for a field.
_rdf_get_default_mapping in modules/rdf/rdf.module
Helper function to get the default RDF mapping for a given entity type.
_search_menu_access in modules/search/search.module
Access callback for search tabs.
_system_date_format_types_build in modules/system/system.module
Builds and returns information about available date types.
_update_7000_field_create_field in modules/field/field.install
Utility function: create a field by writing directly to the database.

File

includes/module.inc, line 790
API for loading and interacting with Drupal modules.

Code

<?php
function module_invoke($module, $hook) {
  $args = func_get_args();
  // Remove $module and $hook from the arguments.
  unset($args[0], $args[1]);
  if (module_hook($module, $hook)) {
    return call_user_func_array($module . '_' . $hook, $args);
  }
}
?>

Comments

display views blocks

if you want to get views blocks in drupal 7, you have to use

$block = module_invoke('views', 'block_view', 'map-block_1');

on drupal 6 it was
$block = module_invoke('views', 'block', 'view', 'map-block_1');

as an alternative, if the

as an alternative, if the display is set as a block I prefer to use

http://api.drupal.org/api/drupal/modules--block--block.module/function/b...

the advantage is that this function will include the contextual links

In this way the title will

In this way the title will not be included.

More specific detail for module

For Drupal 7 :

$block = module_invoke('block', 'block_view', 30);

@arg 1 : module name
@arg 2 : hook name like block_view, block_info
@arg 3 : id or delta of the block e.g 30, map-block_1

for Drupal 6 :

$block = module_invoke('block', 'block', 'view', 30);

@arg 1 : module name
@arg 2 : hook name like block
@arg 3 : $op of hook_block e.g. info, view, configure
@arg 4 : id or delta of the block e.g 30, map-block_1

e.g. to display block:

e.g. to display block:

<?php
 
print render(module_invoke( 'module_name', 'hook_name', 'block_delta'));
?>

to render blocks in Drupal 7 better to use Block API

function block_render($module, $block_id) {
  $block = block_load($module, $block_id);
  $block_content = _block_render_blocks(array($block));
  $build = _block_get_renderable_array($block_content);
  $block_rendered = drupal_render($build);
  return $block_rendered;
}

The above function works

The above function works smoothly.
Thanks for sharing.
Perry.

Shorter

<?php
$block
= block_load('block', '5');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print
$output;
?>

block_render causes notices

The function block_render apprently works and correctly display the title of the block, but it causes a lot of Notices:

Notice: Undefined property: stdClass::$title in _block_render_blocks() (line 856 di /home/.../modules/block/block.module).
Notice: Undefined property: stdClass::$region in template_preprocess_block() (line 939 of /home/.../modules/block/block.module).
Notice: Undefined property: stdClass::$region in template_preprocess_block() (line 940 of /home/.../modules/block/block.module).
Notice: Undefined property: stdClass::$region in template_preprocess_block() (line 943 of /home/.../modules/block/block.module).
Notice: Undefined property: stdClass::$region in template_preprocess_block() (line 944 of /home/.../modules/block/block.module).
Notice: Undefined property: stdClass::$region in template_preprocess_block() (line 951 of /home/.../modules/block/block.module).

yeah same problem here.

yeah same problem here.

The same...

I got the same notices. They appear because when you call block_load with an unknown delta, it creates a default block object only with the module name + the delta (so without $title and $region).

Perfect function for my

Perfect function for my preprocess functions. Love it, thanks

Better and even shorter

<?php
//print out block 26
$block = module_invoke('block', 'block_view', 26);
print
$block['content'];
?>

Doesn't work in D7

Doesn't work in D7

Drupal 7

This is for Drupal 7.

<?php
//print out block 26
$block = module_invoke('block', 'block_view', 26);
print
render($block['content']['#content']);
//dpm($block); //uncomment to view with devel enabled
?>

You can find the correct module name and block id from the url on the configure link on the block administration page.

works

It works for D7

"Better and even shorter" Worked in d7 for me

Worked in d7 for me (http://api.drupal.org/comment/reply/22770/17559#comment-17559). After many try's with a variety of functions, the only one that I could get to work in my node--content_type.tpl.php was this code. I was trying to render a gmap location block into the content page and this is what finally worked (D7.9):

<?php
$block
= module_invoke('gmap_location', 'block_view', 0);
print
$block['content'];
?>

Thanks.

module_invoke and block theme overriding

I could not get block template overrides working with the 'module_invoke'-using code that is listed above and in lots of other pages. Searched for a while and stumbled upon this page. The block_load method listed here works smoothly.

Will this invoke a module for all users of site?

Hi there,

Will the module_invoke be called for all users of the site, or is there a way to only get the module_invoke to be called for a particular user using params?

Thanks very much.

Search block and views block (D7)

Show search block anywhere (delta not needed):

<?php
$block
= module_invoke('search', 'block_view');
print
render($block['content']);
?>

Show views's block which name is 'comments_recent':

<?php
$block
= module_invoke('views', 'block_view', 'comments_recent-block');
print
render($block['content']);
?>

How to use arguments in

How to use arguments in contextual filters in views?

<?php
print render(module_invoke('views', 'block_view', 'DELTA', 'ARGUMENT'));
?>

Not working

if you want to render a views block

or other display, you can use this:

<?php
views_embed_view
($name, $display_id = 'default');
?>

You can also pass additional arguments e.g. for contextual filters like:
<?php
views_embed_view
('view_name', 'block_display_id', 'argument');
?>

See:
http://drupalcontrib.org/api/drupal/contributions--views--views.module/f...

Login or register to post comments