Great module! I need to do some custom contextual filtering on some of the notices shown on my site. To let my custom modules participate in the filtering process, I've added the code below to the end of the site_notice_passed_filters() function. This allows you to do custom filtering by implementing hook_site_notice_filter_notice(). I thought I might submit the change as a very simple feature request, and perhaps the beginning of some API support.

/**
 * Validate a single notice against the filters.
 */
function site_notice_passed_filters($notice, $is_block = FALSE) {
  ...

  // Check for path and role filters if not a block notice.
  if (!$eval_as_block && (!_site_notice_filter_path($notice) || !_site_notice_filter_role($notice))) {
    return FALSE;
  }

  // Allow modules to hook into the filter process.
  $module_results = module_invoke_all('site_notice_filter_notice', $notice);
  foreach ($module_results as $module_result) {
    if ($module_result === FALSE) {
      return FALSE;
    }
  }

  return TRUE;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bjcooper created an issue. See original summary.

bjcooper’s picture

Version: 7.x-1.4 » 7.x-1.x-dev

Updated version.

bjcooper’s picture

Actually, I think this is more efficient:

  // Allow modules to hook into the filter process. We only need to go until
  // someone says no, so use a loop over module_invoke() instead of
  // module_invoke_all().
  foreach (module_implements('site_notice_filter_notice') as $module) {
    if (module_invoke($module, 'site_notice_filter_notice', $notice) === FALSE) {
      return FALSE;
    }
  }

Note that this allows other contrib modules to hook into the access control for Site Notices. For example, I use it to control access to Site Notices based on Organic Group. You can also write custom modules to hide notices based on other condition (like the user having already completed the form the notice is telling tjhem about, for example).

solideogloria’s picture

Priority: Minor » Normal
FileSize
1.26 KB

Created patch. Added site_notice.api.php