Drupal

Drupal in Africa

I recently had the pleasure and honour to help rebuild the BDA foundation’s website using Drupal.
I would like to thank Julie Hinse from Comptabilité Carrier who recommended me for this contract.

Drupal Camp Montreal 2009 over

What a Drupal Camp! That was a lot of fun.

Here are the camp's photos:
http://www.flickr.com/photos/roydeziel/sets/72157622610060732/show/

Enjoy!

(Special Thanks to Omar for inspiration on a successful camp!)

Redirection in Drupal's _submit() functions.

I am working on a website which uses the contrib module "mysite". The client wants me to modify the landing page after you change some config. The right way of doing that would be to use hook_form_alter() and change the redirect value:

$form['#redirect'] = 'newpath';

However, this was not working for me. I found out this was because the author of the module mysite was using drupal_goto() inside the _submit functions. This is not the recommended way of specifying where you want the page to go to after your form was submitted. You have to return the path.

drupal_goto() does not take query string the way I expected.

A friend of mine contacted me about a problem he was having on his site. He was doing a lot of tests with login/logout and he had the login_security module enabled. This little module will ban users automatically if they enter the wrong password too many times.

My friend was getting redirected to a page not found when trying to login and he did not understand why. I looked into it and it took me some time to figure out that the problem was with the way drupal_goto() was being called.

drupal_eval() does not allow you to access context variable. but...

I am currently working on a project which uses the module site_user_list and I wanted to use some variables in my template. The documentation of the module said I could use the variables from the $r array but I discovered that was not working. I found someone discovered the same problem and opened an issue:
http://drupal.org/node/183379

That same person also contributed a patch but I was unhappy with it. I provided my own.

If you want to use drupal_eval() and allow the code inside that to access (read-only) some of your context variables, try this:

Let's assume you want to eval the PHP code found in the variable $code. You might consider doing like this:

$options = array('foo' => 'bar');
drupal_eval('<?php ' . $code . '?>');

This would mean that whatever PHP code found in $code would have no access to $options.

This is why I recommend this:

$options = array('foo' => 'bar');
drupal_eval('<?php $options = '. var_export($options, TRUE).'; ' . $code . '?>');

The var_export() function (php core) will create valid PHP code from your array. You assign that to another variable (could be called anything) and voila. This code will be executed and the values from your $options array becomes accessible (read-only) to your $code.
If the code inside $code tries to change the values of $options, it will NOT change the values of the real $options since it is a copy.

New Assertion: Check for test being found only once

I created a new patch for Drupal 7 simpletest so that we can verify that a piece of text is present on a page, but only present once and no more.
If the text is not present or if the text is present more than once, the assertion fails.

Full details can be found here:
http://drupal.org/node/402804

Passing a function to another function?

Recently I wrote an article about how I handled semaphores in a Drupal project. I want to talk about how I actually implemented it. I needed more than one function to use the semaphore. The goal was to prevent one function to be called when the semaphore was active. The semaphore would get activated when the function would run. Basically, prevent the functions from running at the same time.

Semaphore or Automatic cleaner - built-in PHP

I built a system that migrate all sort of data from one legacy system to a new database. It has to be run every 15 minutes and must start with data from today and work it's way back to the oldest data. It takes some time to migrate that much data so it does one day per 15 minutes.

Some drupal pain about "q=user"

In drupal, when you go to http://www.yoursite.com/?q=user you get redirected right away to http://www.yoursite.com/?q=user/777 (if 777 is your user id and if you are logged in). If you are not logged in, you see the login page.

My client wanted users to be redirected to http://www.yoursite.com/?q=user/me instead. How simple, right? WRONG!

Sometimes, (or often in Drupal) the simpliest thing end up being a nightmare.

I wrote a drupal module to handle this:

function foo_menu($may_cache) {
  if ($may_cache) {
    $items[] = array(
      'path' => 'user',

Drupal Indexing - node.tpl.php is for layout only

If you are working on drupal, I am sure you were asked at one point to display additionnal data on a node page. Or maybe to filter the data. For example, only show tags from some vocabularies, but not all of them. The very first reaction might be to modify node.tpl.php to call some function that will return the new data and echo the data.

Let's assume (for simplicity) that the defualt node.tpl.php looks like this by default:

<div class="node">
  <h2><?php echo $title ?></h2>
  <?php echo $author ?> wrote on <?php $node->created ?><br />
  <?php echo $content ?><br />

Syndicate content