Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
Comment | File | Size | Author |
---|---|---|---|
#4 | site_notice-filtering-hook-2700751-4.patch | 1.26 KB | solideogloria |
Comments
Comment #2
bjcooper CreditAttribution: bjcooper commentedUpdated version.
Comment #3
bjcooper CreditAttribution: bjcooper commentedActually, I think this is more efficient:
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).
Comment #4
solideogloria CreditAttribution: solideogloria commentedCreated patch. Added site_notice.api.php