Codekarate Content

By shane
Mon, 2011-06-27 15:18

Here are two ways to get a list of users in Drupal 6. The first is to get a list of users in a specific role.

$sql = "SELECT u.uid, u.name FROM {users} u
   INNER JOIN {users_roles} ur ON u.uid = ur.uid
   WHERE ur.rid = %d";
 
//replace the 3 with whatever role id you are looking for
$results = db_query($sql, 3);
 
while ($result = db_fetch_object($results)) {
   //do whatever you need to with the results
 }
By shane
Mon, 2011-06-27 11:52

Ran into a situation earlier today where I needed to validate a Drupal username and email address entered into a custom form that would create a Drupal 6 User account (see http://codekarate.com/content/create-user-account-drupal-6-programmatically for more information on the submit handler of the form). There are easy to use Drupal functions to validate the username and email addresses. See the examples below:

//check if this is a valid Drupal username
user_validate_name('USERNAME');
 
//check if this is a valid email address
user_validate_mail('<a href="mailto:test@test.com">test@test.com</a>');
By shane
Fri, 2011-06-17 14:29

The purpose of this post is to provide a little bit of guidance to those Drupal developers who maybe are just beginning, or are at least still in the overwhelmed learning stages. The first thing I want to say, is that learning Drupal (at least for me) was not something that I considered to be easy. I was not at all accustomed to the idea of using hooks so it initially took me some time to learn how to develop for Drupal the right way.

Make sure to also take a look at my 5 Secrets to Becoming a Drupal 7 Ninja Ebook if you are interested in Becoming a Better Drupal Developer. It contains a bunch of ideas and best practices that professional Drupal developers use to help them build and maintain Drupal websites.

Now lets get started.

By shane
Thu, 2011-06-16 16:01

I use the quicktabs module occasionally to display tabbed content. I recently ran into a situation with a complex user profile that caused me to have to display a minipanel with contexts inside a quicktabs block. There was no easy way that I could find to pass the contexts through the quicktabs block to my minipanel. Because of this, I came up with this solution (be warned, it is a little bit of an ugly workaround).

By shane
Thu, 2011-06-16 15:49

Here is a quick issue I ran into earlier today while working on a Drupal 6 website that I wanted to share. This one will be short and sweet.

Lets say you want to create a block in a Drupal module that will only ever be on a users profile page, or perhaps you have another situation where you are adding some code for display on a users profile page. If you are trying to get the Drupal user object of the currently viewed user, here is a quick way to do it.

$user = menu_get_object('user_uid_optional');
By shane
Mon, 2011-06-13 17:25

Typically when performing a database insert in Drupal 6 you use drupal_write_record. However, there is an instance where this does not work as expected. If you are creating a module that has a database table (defined by hook_schema), and you need to populate that table with data from within your install process, you might run into a problem. Lets look at an example.

Lets say you have a simple install file that looks like this:

By shane
Wed, 2011-06-08 15:52

Looking to do this in Drupal 7? See my updated post on how to Create a user account in Drupal 7 programmatically.

There have been a few situations in which I needed to create a user on a Drupal site based on some action. There are many other situations where this might be necessary so I put together a really quick example of how it can work. The code I have below is based heavily on the Ubercart code that creates new users when they purchase a product on an Ubercart powered Drupal site.

 
By shane
Mon, 2011-06-06 13:21

Adding Javascript to a Drupal 6 Module is a pretty simple process. This post can serve as a very simple primer to get you started.

It starts with implementing hook_init() in your .module file.

/**
 * Implements hook_init().
 */
function MYMODULE_init() {
  drupal_add_js(drupal_get_path('module', 'MYMODULE') .'/MYMODULE.js');
}

Then you will need to create a Javascript file called MYMODULE.js in your module folder. Drupal by default comes with the JQuery library. Your Javascript file should look similar to the one below:

By shane
Wed, 2011-05-25 23:26

As I write this, one of the websites I frequent for information is currently down. It is not uncommon for a website (or the server the website is on) to have a problem. I am not sure if the site is going through planned maintenance or if this is unexpected downtime, however it reminded me of a few things.

By shane
Mon, 2011-05-23 14:00

Drush is a very powerful command line utility for creating, managing, and maintaining your Drupal website. There are many things that you can do with Drush, but suffice it to say that if you develop/build Drupal websites and don't currently use Drush, you should most definitely check it out.

Note: If you are looking for help with Drush, check out this link - Drush: Getting started

Pages