Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
It would be great if DrupalChat had a method to allow other modules disable the output of DrupalChat.
I think hook_suppress() was first implemented to suppress admin menu output (#249537: Allow modules to disable admin_menu), and it was later been adopted by admin module and others.
Then, other modules can simply do module_invoke_all('suppress')
whenever they need to disable the output of all these modules. For example, when generating output for a popup, etc.
Implementation of hook_suppress() for DrupalChat could look like this:
/**
* Implementation of hook_footer().
*/
function drupalchat_footer() {
global $user;
- if (user_access('access drupalchat')) {
+ if (!drupalchat_suppress(FALSE) && user_access('access drupalchat')) {
return theme('drupalchat');
}
}
+
+/**
+ * Implementation of hook_suppress().
+ *
+ * Allow other modules to suppress display of Drupal Chat.
+ *
+ * This function should be called from within another module's page callback
+ * (preferably using module_invoke()) when the menu should not be displayed.
+ * This is useful for modules that implement popup pages or other special
+ * pages where the chat would be distracting or break the layout.
+ *
+ * @param $set
+ * Defaults to TRUE. If called before hook_footer(), the chat will not be
+ * displayed. If FALSE is passed, the suppression state is returned.
+ */
+function drupalchat_suppress($set = TRUE) {
+ static $suppress = FALSE;
+ if (!empty($set) && $suppress === FALSE) {
+ $suppress = TRUE;
+ }
+ return $suppress;
+}
Thanks!
Comments
Comment #1
markus_petrux CreditAttribution: markus_petrux commented.
Comment #1.0
markus_petrux CreditAttribution: markus_petrux commentedFix example to invoke hook_suppress(). It should use module_invoke_all('suppress'). Oops!