code

Simple permissions for uploads per node type

19th Aug
2008

Simple bit of Drupal module code from yesterday: permissions are provided for each node type which can have attachments, providing a more granular permission set based on node type. Then, we alter any node add/edit forms and set the #access property for the attachments part of the form based on these new permissions.

Check the code out after the break, hope its of some use somewhere. Does anyone have any thoughts on unsetting form elements like this? Is it a wise thing to do, or is there a better way? Cheers to those who commented, I've modified the snippet accordingly.

Listing authenticated users without roles

1st Jul
2008

Sometimes we'd like to list users who have registered with a Drupal site, but haven't been placed into any proper roles yet via subscriptions, purchases, membership approval or whatever.

Try this join query to get started:

  1. SELECT users.uid, name, created, access, login, status
  2. FROM {users}
  3. LEFT OUTER JOIN {users_roles}
  4. ON users.uid = users_roles.uid
  5. WHERE users_roles.uid IS NULL AND users.uid != 0

Embedding Views in PHP snippets with Views 2

21st May
2008

Just a quickie - embedding views in PHP snippets etc. Sometimes blocks or panels don't quite cut the mustard and we need to directly insert a view via some PHP.

I started off here - the method I've used before to achieve this. There's another howto on Innovating Tomorrow. However, views_build_view, and indeed theme_view, are both no longer part of Views...

After a bit of searching I found mention of a new function; its also mentioned in the Views 2 documentation (work in progress).

So, the resulting PHP is wonderfully simple:

print views_embed_view($view_name, $display_id = 'default');

I was tearing my beard out, so I hope this helps someone.

Some tweaks for a Drupal WoW guild site

26th May
2007

tempestraidspost.pngThe Tempest is was a World of Warcraft guild site built initially on Drupal 4.7 and recently upgraded to Drupal 5. It provides guild membership management via user accounts and roles, forums with public and private access, raid listings with sign-ups and other groovy stuff like private messaging, image galleries and a links/resources directory.

For managing raids and sign-ups we use a CCK type called 'raid' which includes fields for:

  • Date using the Date API;
  • Instance as a drop-down list (see the attached instance_list.txt for the values we use);
  • Notes for anything else, eg what the goals of the run are.

A slighty tweaked Sign Up module allows guild members to sign-up for raid nodes. We also use the Calendar module along with trusty Views to provide both an Upcoming Raids List and a Raids Calendar.

Event Removal module

30th Jan
2007

Event Removal is a small module to handle old events - site admins can choose whether to demote posts from front page, unpublish or even delete them. There are 4.7.x and 5.x versions available below.

Being used on two development sites, so there may be issues. If anyone's interested I'll get this on drupal.org - if you try it in the meantime, comments are welcome here.

Forum Block module

29th May
2006

The result of this afternoon's module emergency. A recent client ran into problems with some block PHP snippets we'd written, which were admittedly written very specifically to work with the client's site and that alone. The inherent weakness in this approach was soon apparent - a few tweaks to the site post-project completion, and the snippets fall on their arses.

So here is Forum Block module, which provides a single block allowing users to post new forum topics to administrator specified forums. Its a damn sight more generic that my original snippets approach, and should work on any site with forum and taxonomy modules enabled.

Its simple, but I hope somebody may find it useful. If anyone shows interest, I'll get it submitted to Drupal projects and CVS. In the meantime, if you have any comments or problems please comment here!