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

markus_petrux’s picture

Status: Active » Needs review

.

markus_petrux’s picture

Issue summary: View changes

Fix example to invoke hook_suppress(). It should use module_invoke_all('suppress'). Oops!