Skip to content

Instantly share code, notes, and snippets.

@dergachev
Created February 1, 2012 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dergachev/1719328 to your computer and use it in GitHub Desktop.
Save dergachev/1719328 to your computer and use it in GitHub Desktop.
<?php
/**
* Invokes hook_greeting() to collect greetings from all other modules.
* Located in greeting.module.
*/
function greetings_init() {
$greetings = array();
// Invoke hook_greeting() to collect all greetings, keyed by module name.
// Can also use module_invoke_all() to achieve the same.
foreach (module_impelements('greeting') as $module) {
//$modules == array('hello', 'howdy');
$function = $module . '_' . 'greeting';
$greetings[$module] = $function();
}
// Allow modules to implement hook_greeting_alter().
drupal_alter('greeting', $greetings);
// Render greetings
foreach ($greetings as $module => $greeting) {
drupal_set_message("Greeting from $module: $greeting");
}
}
/* Implementation of hook_greeting. Located in hello.module. */
function hello_greeting() {
return "Hello there!";
}
/* Implementation of hook_greeting. Located in howdy.module. */
function howdy_greeting() {
return "Howdy, partner!";
}
/* Implementation of hook_greeting_alter(). Located in nasty.module. */
function nasty_greeting_alter(&$greetings) {
$greetings['howdy'] = "Howdy, jerk!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment