[drupal-devel] [feature] Block access by role patch (attached)

flexer drupal-devel at drupal.org
Sat Feb 26 23:36:37 UTC 2005

 Project:      Drupal
 Version:      cvs
 Component:    block.module
 Category:     feature requests
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  flexer
 Updated by:   flexer
 Status:       patch
 Attachment:   http://drupal.org/files/issues/block_access_by_role.tar.gz (2.54 KB)

This is my patch(es) to add support for a per-role basis blocks
How it works (user):
block administrators can select which role(s) could access every block,
via the configure block setting. In the same way one could "Restrict
block to specific content types", now can "Show block to specific
roles". Selecting one or more roles will cause the block to only be
shown if the current user belongs to one of the selected roles. If no
role is selected, the block is showed to everyone. Selecting all roles
or selecting none, has the same effect. Note that Administrator (user
1) is never affected by this restriction.
How it works (developer):
I have added a new table to the system (block_access). It contains the
module, delta and role for each defined block. Permission check is made
in the "list" hook of the block module. A patch is given also for the
*user.module*: when a role is deleted, we need to delete the specific
records in block_access.
Why this is useful:
I use the menu.module very much, so I wondering why there was no way to
create menu (as blocks) with content visible only to certain roles. So,
my patch prevent the menu blocks to be displayed only for certain
roles. I have also create, with this patch, an admin block that say
"Register now ! Blah blah...", visibile only to anonymous users.
Security issues:
None that I could be awaew of...
Performace issues:
Every time a block_list is called, an additional database query is
What the file contains:
The attached file contains:

the block.module patch *block.module.patch*
the user.module patch *user.module.patch*
the MySQL DDL for block_access *block_access.mysql.sql*
the PostgreSQL DDL for block_access *block_access.pgsql.sql*

What to worry about

This is my first contribution to Drupal 
English is not my first language :)


View: http://drupal.org/node/18018
Edit: http://drupal.org/project/comments/add/18018

More information about the drupal-devel mailing list