Adding permissions to a role programatically

I wrote this little bit of code after asking around to find out if there was a way to add permissions by role and came up empty. Ends up there is a nice module for doing this for install profiles and could be used for update functions as well I am sure. I haven't looked at it, but you can check out the Install Profile API.

This apparently has some nifty items that aid in your install profile construction (thanks Boris!), however all I need is to add some checks to some checkboxes on the Permissions page via code, so I am using this:

<?php

/**
* _add_permissions() is a helper function to add permissions by role to the db
*/
function _add_permissions($rid, $permissions) {
  if (!
is_array($permissions)) {
   
$permissions = explode(', ', $permissions);
  }
 
$current_perms = explode(', ', db_result(db_query("SELECT perm FROM {permission} WHERE rid=%d", $rid)));
  foreach(
$permissions as $permission) {
    if (!
in_array($permission, $current_perms)) {
       
$current_perms[] = $permission;
      }
    }
 
$current_perms = implode(', ', $current_perms); 
 
$return = db_query("UPDATE {permission} SET perm= '%s' WHERE rid=%d", $current_perms, $rid);
  return
$return;
}
?>

This made my daughters happy

hello kitty

Draggable Views, a UI sanity saver!

In many instances, I have seen drag and drop (dnd) ordering, rearranging, what have you, used where it perhaps didn't really need to be, but sometimes, there is a real good use for it. I ran into that today.

Views Slideshow Imageflow

Making git a bit easier on me

So lately I have been having all kinds of issues forgetting to do a git pull before doing a git push.

CCK field hook_form_alter ARGH!!!!

Ok, there are a couple of things in Drupal that I pound my head against on a regular basis, and overriding CCK fields using hook_form_alter in a custom module is one of them. You write the code, but you don't see any changes. Weird? Oh yeah.
Come to find out from this excellent blog post that I wasn't the only one to experience this. It stems from the module weight of your module as compared to CCK. The fix is to write a simple .install file for your module and set the weight:

Drupal 7 served from the G1 phone using lighttpd web server, php-cgi, and php-sqlite

If that title doesn't get your attention, you aren't a geek, srsly.

drupal on the g1
After hearing a little interest from some people around irc-land, and from one person who I am considering starting a G1-fund for, I decided that I should try to get Drupal 7 working on my T-Mobile G1 phone. After all, it's an Open phone, right? I might have even uttered those words my wife and I always regret; "How hard can it be?"

Actually, it wasn't that hard :)

Making Plugin Manager work on a Slicehost Ubuntu install with SSH

Recently I found the Plugin Manager module (http://drupal.org/project/plugin_manager) and thought that it sounded wickedly cool, especially because it can allow you to install modules at the click of a button, and run upgrades directly from the admin, fetching all files directly from Drupal's servers. Getting it setup however is another beast altogether, and one that I figured I should document if the need arose to do it again.

My setup is on Slicehost with an Ubuntu server install, where I have root access and can manipulate my server configuration any way I see fit. If you do not have a similar arrangement, I am not sure how you might go about using SSH with this module. Here is how I did it.

Drupal XSPF & Media Mover & FLV Media Player all video Pre-Roll

In case anyone wants to know how to create a pre-roll video that plays before ALL local video content, here is how you might go about it. First, you will want to have the following modules:

After you have that setup, and have gotten your video content type all straightened out, and you have the settings for all of these items correct, then you need to add a little something to your very own custom module to enable the pre-roll video to load before all of the videos. In it you might add the following code:

Banging My Head Against Zen + Views Override in Drupal 5

Here is a little gotcha about overriding a View in a block on a Zen sub-theme in Drupal 5 that I thought I should write down, and perhaps share.

I am working on a Drupal 5 site, and I am using Views. I NEED to override how a Views generated block is themed, and because blocks only have access to the $content string, and I need to access a node variable, I needed to override the view and send my node information to it.

How Drupal is Changing My Life (and Business)

A tiny bit of history...

Four years ago, a very cool musician/web guy asked me to help him do some CSS work for another musician's site he was developing, on a platform called Drupal. I didn't know Drupal very well, but I had played with it, and knew CSS, so I said Sure! The site was cool, and I recall that I was editing all kinds of CSS files in all these different places (where I shouldn't have). It all seemed very complicated with these modules having their own style sheets. I was intrigued! But I was also confused by the taxonomy, and felt it was too complicated for the little sites I was doing at the time. After that project, I returned to doing things the way I had been doing them.

It is really too bad I didn't see the real beauty of Drupal at that time, that I didn't understand it's power, flexibility, and community. They were all there four years ago, but I didn't see them. If I had, who knows what I would be doing now? I might have been smitten by the drop, like that cool musician, Robert Douglass. That was his first Drupal site as well.

Powered by Drupal, an open source content management system