Page content

High Performance JavaScript using Drupal 7's JavaScript API


Summary

In today's web, JavaScript is an essential component of any nice, easy to use website. However, while the basics of JavaScript can be easy to learn, it can be hard to know whether the scripts you are writing are heavy, causing page lag, and making for longer load times.

Drupal comes with an excellent JavaScript API, allowing for the creation of high-performance applications, but it can be confusing to know exactly how to effectively use the API.

Advanced AJAX enabled multi-step forms: creating and altering Drupal entities in custom forms (aka: Wizard forms)


Overview

Sometimes we need to create custom Drupal forms to create or update Drupal Entities, in a different manner than the default forms that we are provided with. In this tutorial, we will look at creating a form 'wizard', that allows a user to create or edit two nodes in a single form.

Example overview

Throughout the world, many companies have multiple branches of their company. The form we will create in this tutorial will create a company, and then a branch that is assigned to that company. This will be done using a multistep form with the following steps:

Creating a multiple Node (Entity) edit form in Drupal 7, with filters, a pager, and sortable columns


This tutorial describes how to create a form containing a list of Nodes in an HTML table, with a pager and sortable columns, allowing for multiple nodes to be edited on a single page. The form also contains a search area, allowing for the filtering of the nodes shown by user submitted values.

Drupal 7: Ajax driven multi-step forms with a non-javascript fallback


As any Drupal developer has learned soon enough, Drupal's Form API is extremely powerful, but with that power come complexity. Building a complex Drupal form to look and behave the way you want is almost an art form in and of itself. This tutorial will discuss how to build a multi-step, #ajax driven Drupal 7 form with a non-JavaScript fallback.

Drupal Simpletest: Debugging hanging tests


Here at Jaypan, we use Drupal's Simpletest to create unit tests, both to ensure that our code has no bugs when we build it, and to ensure that any code added in the future doesn't break old code.

The problem with Simpletest is that if there is an error in your testing code, or anywhere else, the tests hangs, and seems to go on forever. This makes for difficult debugging, when you have no indication as to whether or not there is even a problem, much less what it is.

Drupal 7 View Modes: Consistently themeing content across your site


Introduction: What's a 'view mode', and why do I care?

Here at Jaypan, we have begun using a powerful new feature in Drupal 7, 'view modes', to ensure consistent presentation of data across the site. View modes actually existed in Drupal 6, however there were only two available modes, full and teaser (more on this later). And since Drupal 6 only had one Entity type, Node, these view modes only related to nodes, as there was nothing else to relate to. Drupal 7 came along and opened up an API for other modules to register Entity types other than Node. Many things have been turned into Entities as a result; Taxonomy, User, and Comment are all entities in D7, and at Jaypan we utilize custom Entity types for each project. This means that the same types of things can be done with these Entities, as used to be done with nodes. For example, taxonomy terms have image fields attached to them in D7.

Migrating (not updating) comments (or other core types) from Drupal 6 to Drupal 7


Introduction

In the process of rebuilding my site, I decided to build from scratch, rather than attempting to upgrade my installation. With my old installation, I had tried out multiple modules, changed themes multiple times, and played around with the database when I didn't fully know what I was doing, leaving me with a system that worked, but at times was buggy. For this reason, I thought it better to build fresh and import.

As such, I needed to import the comments from my Drupal 6 installation to my new Drupal 7 installation. This is easier said than done - comments have received a major restructuring, and use different database tables in Drupal 6 than they did in Drupal 7, and the column names the comment system uses has also changed.

Drupal API Firefox search add-on


I regularly search the Drupal API for code. Anyone using Drupal does this. I previously used a Firefox add-on called 'add to search bar' that allowed any search on pretty much any page on the web to be added to the firefox browser toolbar.

However, Drupal user bukem has created two addons that create this functionality, and do it well. Add to search bar, while it worked, never worked the first time, and had no autocomplete. The two search engines bukem has created both work every time, and also have autocomplete, just to make things a little easier.

Calling a function after an #AHAH event (Drupal 6)


In Drupal 6, I've at times in the past needed to fire off a function after an AHAH callback. The problem here is that AHAH is a pre-built set of functions by Drupal, and as far as I can tell, the only function it executes after completion is Drupal.behaviors. However, I personally don't see anything in the Drupal object to differentiate whether Drupal.behaviors is being fired on initial page load, or after an AHAH event. jQuery to the rescue! jQuery offers a nice little .ajaxComplete() function that is fired off after every Ajax event. We can use this function to fire off whatever other function we want when AHAH is complete.

Drupal SVN Deployment Strategy


In the past year, I have started using SVN to deploy my Drupal installations. In the following post I will discuss my own personal SVN deployment strategy. This strategy allows me to work locally on a WAMP installation, and use SVN to deploy my sites to their remote installations.

Disclaimer: By no means am I claiming this is the only way, or the best way to use SVN in conjunction with Drupal. But, it is a method that works well for me, and I thought I would share it with others. If anyone has any comments on how they deploy Drupal themselves, or possible ways I could improve my own deployment strategy, I would love to hear them.

I work on a number of different Drupal installations. I maintain my own site, as well as a number of client sites. In deciding my deployment strategy, I considered the following points:

  • Drupal will be the same across all installations
  • The modules and themes (for the most part) will be different in each installation.
  • I don't want to use SVN for the sites/default/files folder, as the contents of this folder are generally user generated, and should be backed up using other methods
  • I need a way to deploy database backups and keep them for future reference
  • There are some situations where I have altered Drupal core. Most people think that this is an absolute no-no, but rather, the rule of thumb should be 'Don't alter Drupal core unless you know what you are doing'