drupal

Drupal is a mighty fine Content Management System which we at Leafish use regularly. This section contains ideas, code snippets and modules which I thought may come in useful for Drupal admins and developers. I won't be officially supporting this code, but feel free to contact me if you have any problems or suggestions.

See also the list of my official projects on drupal.org (requires you to be logged in to drupal.org).

Role Weights gets Token support and a 6.x branch

22nd Jun
2009

Role Weights finally gets a bit of loving in the form of a 5.x-1.4 release with a couple of new features, namely Token support for a user's lightest and heaviest roles and the optional re-ordering of /admin/user/roles and /admin/user/access forms by role weight. These features were introduced in 5.x-1.3, however 5.x-1.4 also fixes a bug which left orphaned entries in the role_weights table after roles got deleted.

I've also branched for 6.x compatibility (at last) - snapshots from 6.x-1.x-dev should be functional and in line feature-wise with 5.x-1.4, bar Views 2 support. I'd love to improve Role Weights for 6.x: re-writing support for Views 2 and adding drag and drop re-ordering of roles being two areas that need some attention, but I'm just too darn short on time at the moment. As always, patches and reviews are welcome in the issue queue!

As a side note, I found this reference pretty useful regarding some function/API changes not mentioned elsewhere.

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

On "subscribing" to module porting/updating issues

6th Jun
2008

Come on people, STOP IT! You know who you are. "Subscribing" to an issue on a drupal.org project (can we guess which ones, people?) simply fills the thread full of useless comments, cluttering up any valid discussion enough to make any maintainer cry.

So, again, please stop. Bookmark the issue. Use RSS. Visit the Contributed Module Status group on groups.drupal.org, and help maintain the current branches status list - get some links to the relevant issues in there for us all to "subscribe" to!

And of course, if you really want the issue to enter into your "My Issues" queue, then contribute something more worthwhile than "subscribing" or "..."

/rant

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.

6 is the Magic Number

13th May
2008

At last! There were a couple of sacrifices, but I've gone all 6.2! This is the first Leafish site to go live with Drupal 6 (although we do have a big Drupal 6 project in the works) so I've made some notes on the process, and a couple of hurdles I not so much overcame as simply ignored for the time being. Props to all those that have helped get the working modules below up to date.

Resources used:

Read past the break to see how I got on...