Created
February 1, 2012 21:04
-
-
Save dergachev/1719328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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