Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough
Dec 21 2009
Dec 21

Both drush and rsync are handy tools to automate the deployment of Drupal sites. You just have to be careful how you combine them.

In my development environment I have a local CVS checkout of drush and I use rsync to push that directory to the remote production server. This way I'm sure both development and production use the same version of drush without the need to install a CVS client on the production server.

Unfortunately my initial attempts to get drush running on the remote system always resulted in the following error message:

The command 'drush.php help' could not be found.

Initially I assumed there was something wrong with the path to the drush executable or the code that detects the location of the drush.php file but only after a while I found the real culprit.

To reduce the number of files that need to be synced I used rsync's --cvs-exclude option. This option makes rsync ignore certain files and directories in the same way CVS does. For example it will filter out all CVS directories. It turns out that a lot more files get excluded:

RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make.state .nse_depinfo *~ #* .#* ,* _$* *$ *.old *.bak *.BAK *.orig *.rej .del-* *.a *.olb *.o *.obj *.so *.exe *.Z *.elc *.ln core .svn/ .git/ .bzr/

Notice core in that list? Guess in which directory drush keeps major parts of its code! By using the --cvs-exclude option of rsync, my remote drush directory was missing approximately 2500 lines of PHP code resulting in the bizarre error message.

The solution is to stop using the --cvs-exclude option or use the --filter option to tune the list of files to exclude during syncing.

Oct 07 2009
Oct 07

One of the scripts in my bag of tools to check whether a site is still up and running is content-check.pl. This little script compares the hash of a web page against a previously created reference hash. If the content of the web page has modified, this script will detect it and send an email.

You have to be very careful which page you check because even the slightest difference in the HTML source will be detected.

In Drupal you should not use any page that contains a form because each time the form is rendered a unique form id is generated and inserted into the HTML. This results in a different page hash and will cause the script to send an warning email.

Keep in mind that, if you have enabled the User login block, each page contains a small login form and is not a good candidate for monitoring through content-check.pl. You might have to resort to monitoring your update.php file instead.

Jun 09 2009
Jun 09

Last week I received a copy of Matt Butcher's "Drupal 6 JavaScript and jQuery" from Packt Publishing.

The book starts off with a gentle introduction into Drupal modules, Drupal themes and jQuery. These first chapters are pretty boring if you are already familiar with Drupal development but they aid newcomers in getting up to speed.

The next couple of chapters dive into the dark corners of Drupal's JavaScript capabilities. They explain things like Drupal behaviors, the JavaScript translation functions, the JavaScript theming functions and how to use AJAX. Each of these chapters is built around a very practical example that is analyzed thoroughly and each chapter also contains numerous tips about Drupal, JavaScript and jQuery. Good stuff!

I've learned quite a few things while reading this book so if you need to do any JavaScript or jQuery development in Drupal and if the cryptic JavaScript Startup Guide on drupal.org doesn't make a lot of sense to you than this book is definitely for you.

Apr 10 2009
Apr 10

Is writing Drupal tests boring? Maybe. Is running tests boring? Not anymore!

There is a patch for Drupal 7 pending that introduces a couple of new hooks into the simpletest module. These hooks will allow you to listen to the progress of a test run and react to tests that pass or fail. I have already created a new testlistener module that uses these new hooks to execute shell commands.

Some examples:

I have a Dell XPS laptop with built-in LEDs that can be controlled using the dellLEDCtl shell command (Linux). Using these new hooks, I can turn the LEDs green at the start of a test run, make them red when a test fails and turn them off when the test run has completed. This is very similar to the functionality of my Eclipse XPS plugin that shows JUnit results in Eclipse.

Another (typical) example is to have two lava lamps, a red one and a green one. You connect both of them to an X10 device (I have an X10 starterkit from IntelliHome) so you can turn them on/off with the heyu shell command (Linux). The testlistener module allows you to let the lamps reflect the status of the Drupal code. Other people are using this setup in their (non-Drupal) continuous integration environment.

If lamps are too soft for you, you might consider shooting missiles instead.

Drupal testing will never be boring again ;)

Jan 10 2009
Jan 10

I'll be attending 2 major conferences the next couple of weeks.

First of all there's FOSDEM in Brussels on February 7th and 8th. I'm particularly interested in the Drupal devroom on Sunday, but there are plenty of other open source sessions throughout the weekend.

The second conference I'll be attending is DrupalCon in Washington from March 4th until 7th. I expect to pick up a couple of tips and tricks about Drupal 6 and I hope to learn a lot about the upcoming changes in Drupal 7. I'm pretty sure that being among that many Drupalistas will help me to find more ways to give something back to the community.

I never attended FOSDEM nor DupalCon (and I haven't been in the US recently) so I'm looking forward to both events!

Oct 16 2008
Oct 16

Google has just started testing a new service to inform webmasters that their CMS is vulnerable to security exploits. Currently they are only targetting administrators of sites running WordPress 2.1.1 but my guess is that they'll be adding support for other versions and other platforms in the future.

I hope that they'll be adding support for Drupal as well because it doesn't matter how many security issues the Drupal security team fixes, webmasters still need to install the latest security patches and upgrades to make a difference in the field.

Any initiative that helps administrators to keep their sites - running Drupal or anything else - safe is good.

Oct 07 2008
Oct 07

In Drupal, you can provide a description for each term in a taxonomy vocabulary. The default taxonomy term pages of Drupal 6 include the description at the top of each page (if only one term is present). Here's how you can achieve the same thing when using views.

  1. Make sure your theme has a page.tpl.php file. My theme is a subtheme of Zen so I copied the page.tpl.php file from the zen folder into my theme's folder.
  2. Create a duplicate of your theme's page.tpl.php file and call it page-taxonomy.tpl.php.
  3. Edit the new page-taxonomy.tpl.php file and add the following where you want the description to appear (for example at the end of the content-header):
    <?php if ($taxonomy_term_description): ?>
      <div id="taxonomy-term-description">
        <?php print $taxonomy_term_description; ?>
      </div>
    <?php endif; ?>
  4. Edit your theme's template.php file and add the following function:
    function yourtheme_preprocess_page(&$vars, $hook) {
      $term = taxonomy_get_term(arg(2));
      $vars['taxonomy_term_description'] = filter_xss_admin($term->description);
    }
    

After you clear your theme registry - by visting the admin/build/modules page - the term description will be displayed at the top of the page showing your taxonomy_term view.

Sep 27 2008
Sep 27

Lately there has been some discussion about the number of posts (and their quality) on Planet Drupal.

Personally I don't think Planet Drupal is hard to follow because of the large number of posts. There are plenty of other high profile planets with far more posts per day.

Let's compare:

Planet Posts per day Feeds aggregated Mozilla 18.2 234 Ubuntu 17.5 271 Apache 15.9 160 GNOME 14.1 254 Drupal 12.5 261 Android 7.6 21 PHP 6.6 97 Eclipse 6.3 169

Note: The number of posts per day is based on the Subscription trends for the last 30 days of my Google Reader.

The question whether all posts on Planet Drupal are on-topic is harder to answer but in my opinion Planet Drupal is doing just fine. I would say that at least 95% of all posts are Drupal-related. People familiar with Planet Apache will confirm that you have to look really hard to find any posts about Apache software among all those holiday pictures.

It is probably true that not all posts on Planet Drupal have the same high quality writing - I'm not even convinced that this posts has - but that is all part of the mission of Planet Drupal: "Planet Drupal aggregates broadly appealing, Drupal-related blog posts pertaining to the community at large (code, advocacy, marketing, infrastructure etc.)".

In the end, it is really easy to skip a post in your favorite feed reader, isn't it?

PS: I think it is far more annoying that the feed of Planet Drupal contains only teasers instead of full posts. Whenever something really interesting appears I have to click to read the full post. Most other planets only accept feeds with full posts.

Aug 26 2008
Aug 26

Recently I have upgraded a customer site from Drupal 5 to Drupal 6. The site contains a number of custom modules that required considerable work because of some changes in the Drupal API. One of the API changes is the removal of hook_info and hook_auth.

The new authentication mechanism has two advantages:

First of all, two authentication-specific hooks have been eliminated. There is no replacement hook, instead you must use hook_form_alter to replace the built-in validation functions of the user login form. This is a more general and more flexible approach and it shows the power of the current form API. You can check user_login_block and user_login_default_validators for examples.

Secondly, there is a lot more flexibility to do error reporting when authentication fails. In Drupal 5 when hook_auth returned false, Drupal would always display the error message "Sorry, unrecognized username or password. Have you forgotten your password?" even though the real problem might be something else, for example a remote server responsible for doing the actual verification of the password is not available. In Drupal 6 you can fully control which messages get displayed during an authentication failure.

Even though there is some work involved to migrate custom authentication functionality to Drupal 6, the end result is code that is much cleaner and more powerful.

Aug 22 2008
Aug 22

There is an interesting presentation by psychologist Barry Schwartz at TED called "The paradox of choice". He explains why people are not better off when there is too much choice.

He claims:

Some choice is better than none. But it doesn't follow from that, that more choice is better than some.

His explanation makes sense:

The more options there are, the easier it is to regret anything at all that is disappointing about the option that you chose.

I think he has a valid point. A point which is also true in software:

I'm not saying that there should be no choice at all but very often there is simply too much choice and investigating all possible options takes too much time. Luckily Barry Schwartz reveals how to be happy with the choices you make:

The secret to happiness is "low expectations".

You can watch the presentation below or over at TED:

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web