Drupal articles

Drupal node load references : Drupal 7

12th Jul 2011

In Drupal 6, if you called node_load then what you'd be returned would be your own copy of the node to change and modify as you pleased, but in Drupal 7 this was changed. By default, what you actually get back from a node_load is essentially a reference to a global singleton for that node. This has the interesting side effect of meaning that if you change anything in the node object, you are probably changing everyone else's copies of that node too. This is explained in this issue: http://drupal.org/node/154859

So, why should you care? Well, in the right circumstances...

Read more

Multiple conditions for dynamic forms in Drupal 7

5th Jul 2011

Here's a quick follow-up to my original post on Dynamic forms in Drupal 7, as a reply to Wappie08, who asked me about combining conditions in the #states array to add increased control over the display of your form elements. The question:

Hi James Williams, I read your blog post about d7 & #states in the FAPI which is really cool! One problem is that the information is also listed in the drupal.org example module, I was missing one important extra hint: how can you make an IF statement?



I mean:

IF field_1 is '1' or '2'...

Read more

Setting up a Drupal API site for module developers

14th Jun 2011

The code that runs http://api.drupal.org is of course Drupal, and it is essentially just scanning the code it's told to and displaying it in a nice format. You can quite easily set up your own API site that you can use to scan your own custom code, or if you're a module developer, your module's documentation (you do have documentation in the code right?)

I'm going to outline how we can use Drupal and Jenkins to build a really nice system for creating an API site that will get updated on-demand, and will manage itself.

The Drupal site

The...

Read more

Adding the new google plus one (+1) button to your Drupal site

2nd Jun 2011

I am sure someone will roll a module very soon, but in the meantime I thought I would blog about our first experiences in adding the plus one button ...

There is plenty of background on the google plusone button already - http://www.google.com/+1/button

It sounds very simple, and indeed it is - with only one small gotcha that we couldn't find any documentation for. We basically followed the steps outlined here : http://code.google.com/apis/+1button/ which is simply :

  1. Include the google plusone javascript file somewhere on your page - recommended in the footer.

<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>

  1. Work out the layout of your...
Read more

ComputerMinds become Silver sponsors of DrupalCon London

2nd Jun 2011


We are all very excited about DrupalCon coming to London (well London-ish - http://london2011.drupal.org/conference/venue ) - and now that we are Silver sponsors we are literally jumping for joy ... now we just need to think of something to put on our very own exhibitor table ...

Read more

Drupal database prepared statements

25th May 2011

Drupal 7's database layer is awesome, it is built upon PDO and one of the great things about PDO is named placeholders, they allow you to build queries like:


$unsafestring = "this string can contain quotes: ' or other things";
$query = db_select('table')
           ->fields('table')
           ->condition('field', $unsafestring);

The SQL that is sent to the database is:


SELECT table.* FROM table WHERE (field = :db_condition_placeholder_0)

This is sent along with the contents of $unsafestring to replace the :db_condition_placeholder_0 token. Note that this isn't some lame string replacement, but an actual argument for the SQL statement.

This has some interesting implications for converting...

Read more

Facebook share links - controlling the data sent

22nd Apr 2011

Not strictly a Drupal post this, but something that I was playing with yesterday that I was really struggling to find any documentation on. We wanted a simple "share" on facebook link, we didn't want to go through the process of creating an app and using the opengraph API - instead we just want to use the simple sharer.php script but have a bit of control over what is being shared.

The basic approach is you are providing a link to http://www.facebook.com/sharer.php?s=100 which is the basic share page (typically this is shown in a popup).

By adding querystring params we...

Read more

Storing data in Aegir

5th Apr 2011

[Aegir][aegir] is a very clever Drupal hosting system built using Drupal and Drush. It is divided into two parts: the frontend and the backend. The frontend is essentially just a standard Drupal site that stores its data in the database and then some drush scripts that manipulate the data. The backend (provision) is just a collection of drush scripts, and it stores its data in [Aegir contexts][aegir_contexts] which are essentially just arrays of data stored in text files on disk. One of the most mysterious processes in Aegir is sending data from the frontend to the backend to be stored...

Read more

Aegir tasks daemon

29th Mar 2011

[Aegir][aegir] is a very clever hosting system for [Drupal][drupal] that sites and provisions them on various servers and does lots of clever things. One of the clever things that it has had for a while is a task queuing system. You can ask Aegir to lots of different things all in one go, and Aegir will queue them up and run them at its own pace. This provides a really good separation from the front-end Aegir website and the back-end Aegir scripts.

We've been using Aegir in production for just under a year, and one thing that has bugged me...

Read more

Setting default drupal theme during installation : programatically install a drupal theme

25th Mar 2011

Here's a quick post that will be a reminder for us as much as anyone else! Setting the default theme during installation using an installation profile is surprisingly hard in Drupal 6, and easier though not obvious in Drupal 7. In Drupal 6, we used the wonderful Install Profile API module, which allowed us to do it in just a few lines in an install task:


  install_enable_theme(array('my_theme', 'garland', 'rubik'));
  install_default_theme('my_theme');
  install_admin_theme('rubik');

In Drupal 7, here's the code I use in my install task:


  // Any themes without keys here will get numeric keys and so will be enabled,
  //...
Read more