Introduction to YAML in Drupal 8

YAML is a data serialisation format that is both powerful and easy for us humans to read and understand. In Drupal 8 it’s used where Drupal needs a list but doesn’t need to execute PHP. One of the reasons why YAML was chosen for Drupal 8 is because it is already used in Symfony.

Read more »

Topic: Drupal 8,

Drupal site builders - why you should start Drupal module development

You build Drupal websites. You know which modules to download and configure and how to make a pretty slick website. You might be able to use Views to build up complex queries to add some fizz to sites that you build. You might be able to create various content types and image presets. You might even know the delights of Context, Panels, Rules etc. But you might be feeling like you want to go beyond downloading, installing and configuring modules. Do you seek more freedom to do what you want? Do you have problems to solve that require a finer touch than using existing modules? Or do you just want to increase your skill level?

Read more »

Topic: Drupal 7,

How to wrap a Drupal Views field in any HTML element

In Drupal Views, you can wrap a field in a basic element (such as div, span, H1, H2, p, strong). But sometimes you are going to need to wrap a field in an HTML element that is not available in the list. For example, if you have an image field that and need to wrap in a <figure> element (this is the example we will use for this tutorial). This can be pretty confusing at first, but fortunately there are a few methods available to get the job done.

Read more »

Single search box with multiple fields using Drupal Views

Searching on fields in Views is made possible by adding an exposed filter for the relevant field. You can search on multiple fields by adding multiple exposed filters. But what if you want to have one single search box searching multiple fields? This is a very common requirement.

Read more »

How do you place a block in a Twig template

There are various ways you can add blocks to regions in pages in Drupal. You could add it in the block interface, use Panels or Context. But what if you just want to place a block directly in a Twig template?

Read more »

How to customise content in partial Twig templates

Using partial Twig templates is a great way to organise your frontend code because you can reuse code fragments in multiple templates. But what happens if you want to use the same partial template in multiple places and customise its content slightly?

Read more »

How Drupal returns a page request

You hit a URL and Drupal gives you a page back. Magic! But perhaps you are wondering, what is Drupal doing under the hood? You know that putting it down to magic is not going to help you to create your own custom modules.

Read more »

A gentle introduction to Namespaces in Drupal 8

Drupal 8 represents a major shift away from “Drupalisms” to mainstream object-orientated PHP. Experienced developers who are used to other frameworks like Symfony, should find it much easier to pick up Drupal now than they would have in Drupal 7 and previous versions. But this shift presents challenges for those of who are used to the Drupal 7 way of doing things and aren’t necessarily up to speed with all the new PHP best practices.

Read more »

Creating a modal in Drupal 8 with one line of HTML

Modal dialogs are incredibly useful on websites as they allow the user to do something without having to leave the web page they are on. Drupal 8 now has a Dialog API in core, which greatly reduces the amount of code you need to write to create a modal dialog. Dialogs in Drupal 8 leverage jQuery UI.

Read more »

Easy way to find the Drush command you are looking for

Both Drush and Console have built-in help. If you type drush, you will get a long list of available commands. If you type drupal, again you will get a long list of available console commands. If you can’t remember the exact command to use to do what you need, you can scroll through the long list of commands to find the one you want.

Read more »

Run Elysia cron from Drush

Elysia Cron is an extension to Drupal’s standard cron system. With standard Drupal cron, all cron jobs are run at the same time. Elysia Cron gives much more control and allows you to set different intervals for each cron. Elysia cron does not actually run cron, instead it schedules what should be run when the standard cron is run. It does this by skipping certain cron tasks if they are setup to run less frequently than the current crontab settings. You just need to setup the normal Drupal cron to run at regular enough intervals.

Read more »

Transitioning from Drupal 7 to Drupal 8: programmatically creating routes and menu items

Routes and menu items are a critical part of the Drupal system. Without them, users would not be able to access the content of a website or any other page. Conceptually Drupal 7 and 8 are the same: map a URL to a function that is responsible for getting and returning the content. But the way it is implemented is completely different (as is the case with most things under the hood between Drupal 7 and 8).

Read more »

Drupal Tutorials

Hi, I’m Blair Wadman. For the past decade, I’ve been on a mission to make learning career-enhancing skills in Drupal as easy as possible.

Read more »

Introduction to Annotations in Drupal 8

Annotations are another one of the new concepts in Drupal 8 to wrap your head around. Annotations are written as PHP code comments above a class or function and contain metadata about the function or class.

Annotations are used by other PHP projects. For example, Symfony2 uses annotations for routing rules and Doctrine uses them for ORM related meta data.

Read more »

Topic: Drupal 8,

Create your first Drupal admin interface

One of the key features of a Drupal module is an admin interface. An admin interface enables you to make a module’s settings configurable by a site editor or administrator so they can change them on the fly.

Read more »

Topic: Drupal 7,

Introduction to PHP short array syntax

Drupal is full of arrays, even in Drupal 8. But when you look at an array in Drupal 8, you may be left wondering why they look different to how they looked in Drupal 7. The reason is that the Drupal code standards now recommend using short array syntax.

Read more »

How to add a View block directly to a template in Drupal 8

The problem

You have a home, section or landing page and you need to add blocks from the Views module. You can use modules like Context, Panels or the new Drupal 8 Layouts to add blocks, including View blocks. But sometimes you just want to do this programmatically in the theme without messing around with another module and all the overhead that includes.

Read more »

What is a Drupal developer?

As the Drupal market continues to rock and roll, more and more clients need “Drupal Developers”. But what exactly is a Drupal Developer? A Drupal Developer is someone who knows Drupal right? Right?!

Read more »

Delete all nodes from a particular content type using devel generate

You’ll often find yourself having to delete all content for a particular content type. You may have tested imported content via feeds and you then need to delete what you’ve imported. Or content was created that is no longer required. Manually ticking everything in the content list is fine if you have just a handful of nodes, but if you have a lot of content to delete, it can get very time consuming.

Read more »

Why Drupal cron is not running as often as you think and how to fix it

You set up a Drupal site for a client and after launch, they complain because important things are not happening. Search is not being updated. Backups aren’t being run. Boost is not being cleared. Logs are not being pruned. All these things should run automatically when cron is run (Drupal comes with the ability to run cron automatically) at specified intervals, such as every 3 hours. So when does cron actually run, if not at the specified interval?

Read more »

Create a Drupal 8 module using the Drupal Console

Developing custom modules in Drupal 8 is a daunting prospect for many. Whether you’re still learning Drupal 7 module development or are more experienced, Drupal 8 represents a significant shift in the underlying architecture and the way modules are constructed.  

Read more »

How to create a custom block and assigning to a region in Drupal 8

One of the many changes in Drupal 8 is adding a block to a region. The block interface has been pretty consistent over the years, so changes to how it works can be confusing at first. You do something over and over again and then “Wait a minute! Things have moved, what do I do?!”. But never fear, the new way of adding blocks to regions is pretty straight forward once you get your head around it.

Read more »

Transitioning from Drupal 7 to Drupal 8: programmatically creating blocks

If you are used to creating Drupal 7 modules, one of the major challenges of moving to Drupal 8 is all the changes under the hood. Almost everything has changed and that can be very overwhelming. But it doesn’t have to be. One method to learn how to create Drupal 8 modules is to compare it to what you are used to in Drupal 7 module development.

Read more »

Need to quickly roll back your Drupal database? Restore it with just one click

With a click here, and a click there, it can be really easy to mess up a Drupal site, especially if you are fairly new to it. It doesn’t have to be you, in the hands of your manager or client, they can end up breaking the site. Setting the correct permissions will help reduce the risk of this, but sometimes people want more permission than they really should have. And when the site owner comes to you and says - “I broke all the things!” - you immediately wonder when the last backup was. Are backups even running? How do I restore from a backup! Help!

Read more »

Topic: Drupal 8,

Guide to Ultimate Cron

Drupal comes with its own built in cron. This means that you can add your own job to the list of jobs that are executed when the Drupal cron runs.

Read more »

Create your first Drupal 8 module

Drupal 8 is (almost) here and if you are a developer, it is time to start learning Drupal 8 module development. Module development in Drupal 8 represents a major shift from Drupal 7. This is the first tutorial in a series where I’ll be going through the process of learning Drupal 8 development. The module that we create in this tutorial is as simple as it can be and is aimed at helping you get a feel for the module structure.

Read more »

Moving from theming in Drupal 7 to Drupal 8? Overview of key changes

Drupal 8 represents some major changes to the way we work with themes. There is now Twig, asset libraries, component based CSS, to name a few of the changes. If you are used to working with themes in Drupal 7, all these changes can be overwhelming. But it is well worth the effort - building themes in Drupal 8 is a much improved experience.

Read more »

How to move private repositories from Github to Bitbucket

Github is a great service and remains the epicentre of open source code. But for a single developer paying for private repositories, its payment plans don’t make a lot of sense. This is because they charge by the number of repositories you have. I tend to have quite a few small private repos for various projects, so the cost creeps up pretty quick. I have absolutely no objection paying Github for private repos, but the pricing structure does need to be sensible.

Read more »

Add an additional validation function to an existing Drupal form

There are many reasons why you might want to add extra validation rules to a Drupal form. This is a simple tutorial on how to add a validation function to an existing form that is generated from a module that you have not created yourself. It could be in a core or contributed module.

The problem

A form has been created by another module, but we need to add additional validation.

Read more »

Topic: Drupal 7,

Freelancing tools

Every professional needs great tools. Fortunately for us freelancers, there is a tonne of tools at our disposal to make our lives easier, more productive and keep our clients happy.

Read more »

Prevent image from shrinking with Flexbox

Flexbox is a relatively new CSS mode that makes it a lot easier to create awesome layouts. One of the features of the Flexbox model is that elements in a single row will shrink in size as the amount of available space is reduced. For example, if you have a row of elements and you decrease the width of the browser, the elements will shrink in width as the width of the containing element reduces. This is necessary in order to keep the elements on a single row.

Read more »

Override Drupal 7's node template for a content type

When you first install a Drupal 7 site with a base theme, you’ll get a couple of standard templates such as html.tpl.php, node.tpl.php and page.tpl.php. But often you are going to need to create a node template for a specific content type.

Read more »

Review of Drush User’s Guide book

Drush User's Guide coverThe Drush User’s Guide, by Juan Pablo Novillo Requena, is a fairly short technical book, at just over 120 pages. Like meetings, the shorter the better for technical books. It is easy to read, concise and well laid out. If you are new to Drupal, this book is not for you. If you build sites in Drupal but are new to Drupal development (module development), then you will find this really useful. If you are a Drupal developer who writes custom Drupal modules, you will find this book essential reading. I have used Drush for a few years and still picked up a thing or two.

Read more »

A better way to style Drupal blocks

To style a block, you first need a way to target it in CSS. When you inspect a block’s HTML, you will see that it has a block ID selector. You can use that to target the block in CSS. But this is not the best way to style blocks in CSS. It can very quickly become hard to maintain. There is a better way, but first, lets look at how to do with the block ID.

Read more »

An introduction to preventing SQL Injection in Drupal 7 modules

If there is one fear that most developers experience, it is the fear of security vulnerabilities with the code you have written. Bugs are one thing, but security holes that can be used to expose user data or wreck havoc on the database are the cause of many a nightmare. One of the most common forms of attack is SQL Injection. SQL Injection involves injecting malicious commands into a query, usually via some form of user entry.

Read more »

Automate Drupal site updates with a deployment module

Much of the work you do when building Drupal sites revolves around enabling and configuring modules, clicking various admin forms and updating settings. These settings are stored in the database. You should make changes to Drupal sites locally first and not directly on the live site. But changes you make to your local Drupal site need to be replicated on your live site. This tutorial is a walk through of how to automate these changes by storing them in code in a Site Deployment module. No more clicking and configuring multiple times!

Read more »

How to backup your Drupal database to Amazon S3

We all know the importance of backing up the database for each Drupal site we build and maintain. But it is not uncommon for this to be put on the back burner and never actually implemented. Fortunately, it is really easy to setup with a combination of Amazon S3 and Backup and Migrate.

Read more »

How to add no-follow to Drupal comment links

Do you get a lot of comment spam? I do. Spam prevention services like Akismet and Mollum do a great job at stopping a lot of the spam. But what happens if a user leaves a good, on topic comment and includes a link back to their site, or another site? By default, search engines like Google will treat that link as a vote towards the target site. As far as it is concerned, you added the link. This can be bad for a couple of reasons, the main one being what is known as a bad neighbourhood. If Google does not like the target site and you link to it, you can become part of its neighbourhood. You do not want that!

Read more »

Improve Drupal email delivery rates by using Mandrill

Recently one of my clients had a problem with a large portion of transactional email never being seen. The emails were being directed to the recipients’ spam folders and were generally being over-looked. These were important emails regarding things like membership confirmations, invoices and event information and were critical to the experience of the members.

Read more »

Learn how to change an existing Drupal form

Changing an existing form is one of the first things that new Drupal developers will learn how to do. It is a natural extension from site building, where you might need to change one thing on a form created by a core or contributed module. One of the benefits of using the Form API to construct forms is that any module can alter any other modules form. In this tutorial, you are going to learn how to alter a Drupal form.

Read more »

Updating and reverting Drupal 7 Features with Drush

Updating and reverting is an essential part of managing Features on Drupal sites. After you create a Feature, if you make further configuration changes the Feature will become overridden. This means that the configuration settings that you have made in the UI are stored in the database but do not match the feature module code.

Read more »

How to enable/disable modules programmatically

When you add new modules to your project, you may be used to enabling them in the modules page (admin/modules). This does mean that you need to remember to enable these modules on the live site (and any other site in your pipeline).

Read more »

My top 10 Drush commands

Drush is awesome. Having Drush commands at my finger tips saves me a lot of clicking in the Drupal admin interface and ultimately makes me more productive. If you are new to Drush, you might find the large number of commands available overwhelming and not know which ones to start with. Here are the 10 Drush commands that I use most often - the ones I use every single day when developing Drupal sites.

Read more »

Top 10 Drush commands - follow up

I recently posted my top 10 Drush commands. In the blog post comments, over email and Twitter, a bunch of people let me know their top commands and tips. This was such great feedback, I decided to write up the list as another post. Here is the top 10 Drush commands from the fine folk who contributed (in some cases, they are variations of a command that I listed in my post).

Read more »

Save time managing Features with Drush

The Features module is a vital tool in the Drupal developers and site builders arsenal. It is used to export configuration that is held in the database to a Drupal module, making it easier to version control, deploy and use on other sites. Like the rest of Drupal, you can do everything in the UI but this can be time consuming. Fortunately Features comes with a set of handy Drush commands which should save you valuable time. Let’s go through them one at a time.

Read more »

Components of a Drupal site

The three most important elements of Drupal are nodes, blocks and users. Nodes and blocks are important because they are what people see. Users are important because this is how people can administer or be a member of a Drupal website.

Read more »

How to (almost) eliminate comment spam with Drupal

A few weeks ago I was ready to turn off the comments on my blog. Despite having Mollom running, I was left with a non trivial amount of spam comments to manually deal with each day. It felt like a waste of my time. I love the great comments I get. But there are always people who want to ruin the party, and for the web, it is spammers.

Read more »

Changing existing URL paths in pathauto

Using the Pathauto module is a quick and easy way of automatically creating meaningful URL’s. Instead of having to type in a URL path manually for each node (page, story etc) yourself, it will do it automatically based on set criteria, like the category it belongs to and the title.

Read more »

Boost your Drupal website

Boost is an amazing Drupal module that can dramatically improve the page speed performance. This can improve the experience of visitors and help a web site cope with unexpected surges in traffic.

Read more »

Resolving "Fatal error: class not found" in Drupal 7

You have gone through your regular module update routine and cleared the cache. Suddenly you are presented with a PHP Fatal error, because a class can’t be found. Your Drupal site won’t load and you can’t run Drush commands. All you get is the fatal error blocking the site.

Read more »

Override Drupal 7’s page template for a content type

Creating a page template for a content type gives you a lot of control over the structure of the page. While Drupal will automatically pick up a node template for a content type, if you use the right naming convention, it will not for a page template. Fortunately it just takes a few lines of code and you can create a page template for any content type you choose.

Read more »

Drupal: How to structure your modules directory

Ever feel like your Drupal code is becoming a disorganised mess? Most Drupal sites contain a decent number of contributed modules. Before long, you might write your own custom modules. And then you might generate Features, which are also modules. You end up with a heck of a lot of modules! You could dump them all into the modules folder, but then how will you distinguish between what is custom and what is contributed? Sure you know what your custom modules are, but you will have to search for them through that long list of all those modules. If only they could be more organised!

Read more »

Drupal London Meetups

There is no shortage of Drupal meetups in London. They are a great way to meet like minded people, share knowledge, make friends and find work. Here is a roundup of the main Drupal meetups in London:

Read more »

Learn how to add custom validation to an existing Drupal form

Form validation is an essential part of any web system. You need to ensure that the user has added valid data and if not, show them a meaningful error message. Validation functions are normally implemented in the module where the form is defined. However, thanks to Drupal’s hook system, you can add a validation function to any Drupal form, even if you did not create the form. In this tutorial, you will learn how to add a validation function to the node article form. This is the form where you add content to the article content type and can be found here: node/add/article

Read more »

Why you should not always use Drupal Features for settings, and what you can use instead

The Drupal Features module covers a lot of our needs with automating the deployment of database settings for Drupal 7. It allows you to export configuration to code and nicely wrap it up as a module. This means you easily deploy your changes to the live site (or a staging site) without having to repeat the configuration changes. It also means you can apply the changes to a different site.

Read more »

Recreate a Drupal Feature

In the first part of this Drupal Features guide, you learned why Features is a vital tool for Drupal site builders and developers. We then created a new Feature, which contained a Todo list content type. In this part, you will create a View to display the todo list in a block and add the View to the Feature by recreating it. Views are not the only thing you might add to a feature module. You can add a whole range of components, such as image presets, context and strongarm (for variables) to an existing feature.

Read more »

Create a module without writing any code with Features

As you build Drupal sites, define content types, setup Views and image presets, you end up making a lot of configuration changes. One of the problems with Drupal (up to and including Drupal 7) is that content and configuration is all stored in the database. I’m sure you have experienced the real headache when you want to move the content types, views and various configuration changes from a development site to production site or to another site entirely. You end up repeating configuration changes again (and again).

Read more »

Essential Drupal development tools

You can build Drupal websites with just a few tools, such as a code editor, browser and dev environment. While it is not necessary to use additional tools, tools do make your life easier and can save you a tonne of time and improve the quality of your work. So let’s take a look at the essential tools to use to develop with Drupal.

Read more »

How to validate a single Drupal form element

You may be used to adding validation functions for an entire form, but what if you just want to validate an individual form element? Do you really need a form wide validation function for a single field? What if you just want to check that a user submits a number in a field?

Read more »

DrupalCamp London - a weekend without tents

I had the privilege of attending DrupalCamp London on the weekend of March 2nd and 3rd. I wasn’t really sure what to expect but was hoping it would be like a mini DrupalCon. I was not disappointed one little bit. It was very well organised, the talks and BoFs were fantasic and there was a great atmosphere. The best bit for me was that it was more intimate than a DrupalCon and I found it easier to get chatting to a variety of people.

Read more »

Symfony Live London Recap

Last week I had the privilege of attending my first Symfony conference, Symfony Live London. I have not done any Symfony work before (apart from some video training by Knp Labs) but I am very keen to get into it. Commercially, I have been doing mostly Drupal for the last five years, and it is time to expand my horizons. Deciding on which framework to get into next was made easy with the decision to use Symfony components in Drupal 8. Learning Symfony will enhance my ability to offer top Drupal consulting as well as stand alone Symfony. Symfony components are also going to be used may other leading PHP projects, so it is quickly becoming a must have skill.

Read more »

Add existing project to Github

So, you have been working on a project locally and then decide you really should version control it and share it with the world. One option would be to create the repository on Github, clone it locally and then copy all the files across. But it does not have to be so messy. Here is how you add an existing project to Github without cloning it first.

Read more »

MAMP setup notes

MAMP (Mac Apache MySQL PHP) is relatively easy to set up, but there are a few things that I had to change. Here are my notes on the changes I made.

Read more »

Subversion Branching and Merging for Sprints

On my current project, we create a branch at the beginning of each sprint and maintain a clean trunk. All code from the sprint is committed to the sprint branch. At the end of the sprint, we merge the sprint branch into trunk (assuming it passes QA). This is pretty much the same setup as feature branches. Here are a few notes and snippets for this type of setup.

Read more »

Setting up debugging with Komodo IDE and xdebug (and virtual machine)

Debugging with an IDE like Komodo (or another debugging tool) will save you a whole world of pain. It will save you through dropping in print_r all over you code and allow you to step in and out of your code as it executes with ease. The first stage, of course, is setting it up and that is the focus of this tutorial. 

The Environment

 I use a Mac, but run a virtual machine with Linux (Ubuntu Server). I mount the files using NFS. The steps in this tutorial will work equally well if you run Linux natively. If you do not run Linux at all, you will need to adjust some of the steps.

Installing xdebug

First we need to install xdebug with the following command:

sudo pecl install xdebug

Now we need to add some code to the php.ini.

sudo nano /etc/php5/apache2/php.ini

Add the following to the bottom of the file:

xdebug.remote_host=your mac's ipaddress or localhost

You will need to check to ensure the zend_extension path is correct:

cd /usr/lib/php5 

ls -la

Do you see 20060613? If not, there should be another folder with a set of numbers. Change directory into that to sure is there and use that folder name instead of 20060613. What you put in xdebug.remote_host will depend on whether you are running Linux in a virtual machine or not. If you are, add your Mac's IP address. If not, add localhost.

Reload apache:

sudo /etc/init.d/apache2 reload

Setting up Komodo

Go to Preferences and then Debugger.

Komodo Debugger Preferences 

At this stage, we want to ensure that the debugger breaks on the first executable line. This is important for mapping the URI's, which we will do in a sec (required if running in a virtual machine).

Initial break behavior: Break on first executable line

Komodo break first executable 

Preferences -> Debugger -> Connection: Komodo should listen for debugging connections on: a specific port: 9000


In the main Komodo menu, we need to tell Komodo to listen for debug connections. 

Debug -> Listen for debug connections: Select this. 

Komodo Listen Debugging 


First debug session

Go to the page you want to debug. It would be best to go to the home page of the project you want to debug. Append the URL with: `?XDEBUG_SESSION_START=1`. This will start the debug session. You will get a dialog box stating a remote application has requested a debugger session, would you like to debug now. Click yes.

If you are running Linux in a virtual machine, you should be asked to map to the file. You need to navigate to where the actual file is. If you have mounted the files (using NFS or similar), then select local, navigate to the mounted folder and then the correct file in your virtual machine. It would be best to map the root of the project rather than individual files. 

Break points behaviour

In one of the previous steps I asked you to ensure that the debugger will initially break on the first executable line. You can leave it like that if you want, but you may prefer it to only break on break points that you specify. To change it, go back to Preferences and then Debugger and change the initial break behavior to "Run to first break point".  

Preferences -> Debugger: Initial break behavior: Run to first break point 

Komodo break on first line 



Hopefully this has helped you set up debugging on Komodo using Xdebug with a virtual machine. In a future tutorial, I will walk through some examples of how to actually perform the debugging.

Read more »

Count of duplicate values in MySQL table

A client is using the Drupal node title module and, as part of an SEO review, I want to see how many duplicate meta titles there are. The following is a simple MySQL statement that I ran to get the answer:

Read more »

Drush PHP memory limit

With the default PHP settings, Drush will probably get a fatal error because the PHP memory limit is too low. Thankfully, the solution is very simple.

Read more »

DrupalCon London 2011

I was fortunate enough to be part of the biggest DrupalCon so far, DrupalCon London. 1,751 Drupalistas were there, attending a total of 73 sessions, participating in code sprints, making friends and having a good time.

This was my first DrupalCon and it did not disappoint. There were some great sessions by very talented presenters and I thoroughly enjoyed them. The best aspect of DrupalCon for me was the real sense of community. Drupal is, after all, as much about the community as it is about the technology.

DrupalCon London Group Photo

Group photo of the Drupalistas

My Session Highlights

Designing the Sustainable Web

The biggest highlight for me was the keynote on Thursday: Designing the Sustainable Web, by The Web Standardistas. It was a relaxed and amusing performance by Christopher Murphy and Nicklas Persson. They took us through the history of design and how design principles from early 20th Century are relevant to web design today. Particular emphasis was put on grid system and they showed us some great examples of grid implementations.

See video

State of Drupal 2011

The first keynote was by Dries Buytaert, Drupal's founder and project lead. He took us through the findings of the State of Drupal survey, which contains some very interesting stats. One important trend is that a lot of bigger organisations are standardising on Drupal as a platform, especially in the media industry. In other words, rather than using many different platforms (Wordpress for blogging, phpBB for forums etc), Drupal is being used as a single platform meeting many requirements. I have worked quite a lot in the media industry and this is something I have seen as well in the last few years. Adoption is increasing in not only media, but also finance, government, high tech and academic industries. Dries described the adoption of Drupal as a global phenomena.

See video

This Code Stinks!

I thoroughly enjoyed This Code Stinks! by Larry Garfield. Larry talked about 7 common types of code smells in Drupal projects, how to detect them and how to address them. Larry was an energetic and engaging presenter who really brought the topic alive.

See video

Node.js and Drupal

Node.js seems to be getting a lot of developers very excited. In a nutshell, it is server side Javascript using Google's super fast V8 engine. The Node.js and Drupal talk was a nice introduction to node.js and how and why to use it with Drupal. One of the presenters, Justin Randell, is using Node.js for the new version of the chat room module and this was used as a great example of why node.js is useful for Drupal.

See video

Other notable sessions I attended

Socialising and Networking

At any conference, networking is even more important than the sessions. Being a platform built by a community of contributors across the globe, DrupalCon is the time when everyone gets together. There was a real sense of community and buzz around the conference. There were plenty of social events during the evenings, including a pub crawl from Tower Bridge to Southwark Bridge, Batman Live and offical party in the O2 , quiz night, curry night and pub visits in Croydon. I met some very genuine and cool people and caught up with old friends and work mates. And that is what makes Drupal great - the people you meet and get to know - the community.

DrupalCon London renewed my enthusiasm for Drupal. I will definitely be attending another DrupalCon soon - hopefully Denver or Munich!

Read more »

DrupalCon Munich 2012 Recap

DrupalCon Munich was my second DrupalCon and it proved to be as good as my first. I flew into Munich on Monday night and didn’t really stop until I left on Thursday night. I should have stayed for the code sprints on the Friday, but had a holiday to get to!

Read more »

How to suppress validation errors with a back button on a Drupal multistep form

Multistep forms are a great improvement to the user experience, especially if a form has a lot of fields. Rather than users having to deal with an overly long form, you can present them with a series of steps with just a few fields on each. Most multistep forms feature a back button. The problem is, when you have required fields on a particular step, and the field is not filled in, the user will get a validation error when hitting back. This is because the Drupal form is being validated and all of the necessary validation handlers are being called and validation rules processed. Receiving a validation error when simply trying to go back on a step is not a great user experience!

Read more »

Improving Drupal Speed

Drupal is a fantastically powerful content management system. But that power comes at one very significant cost, speed. A Drupal powered site may suffer from slow page loads.

Read more »

How to contribute a patch to

Lets say you have found a bug in someone else’s contributed module. It happens! You could raise an issue in the issue queue for that module, or you could fix it yourself and contribute the fix back to the community. You are not always going to be able to fix it yourself, but if you can, you should, as this will help everyone, not just the module maintainer.

Read more »

Hierarchical Select Pathauto termpath breaks with multiple vocabulary

The codebase I am working on uses hierarchical select with taxonomy to make it easy for editors to tag from nested terms. Pathauto is used to create the URL alias for the content type. We need both the parent and child terms in the URL, so use this token: [save-lineage-termpath-raw].

However, a problem occurs when you add a second vocabulary for the same content type. This breaks pathauto and it can not create the URL alias. Fortunately there is another token to save the day: [save-lineage-termpath-raw:vid]. 

[save-lineage-termpath-raw:vid]. only has output when terms are present for the vocabulary with the specified vid.

In this case, the vocabulary that I want to use with this path is the first one, which has an ID of 1. So the token is: [save-lineage-termpath-raw:1]

At this point, alarm bells start ringing because when you save the pathauto form, you will get a validation error. 

The Pattern for all Car review paths is using the following invalid tokens: [save-lineage-termpath-raw:1].

Fortunately there is a patch for this already, which you can find here:

If you don't know how to apply a patch, follow these steps:

  1. Save the patch file to your machine (in this case:  /Users/blair/Sites/Drupal/patches)
  2. In terminal, navigate to the root of the hierarchical_select module folder (sites/all/hierarchical_select)
  3. Run the following command: patch -p0 -i /Users/blair/Sites/Drupal/patches/hs_taxonomy-token-list.patch
Read more »

MySQL Type Casting

Example usage - if a field is a varchar and you need to sort by a number. It will sort it alpabetically, instead of numerically. Type casting will convert it to an altenative data type.


Read more »

MySQL Server Has Gone Away Error - Cause & Solution

The MySQL Server has gone away error can happen when trying to restore a database. There are a few possible causes for this and one of the most likely is that the database is very big in size and the packet size in MySQL is not big enough.

Read more »

Open a link in a new window using jQuery

There are times when you pay want to force links to open in a new window. It could be to open terms and conditions, adverts or external links. Please note that some believe that you should never force a link to open in a new window as that decision should be left to the user. I will not debate this here, but rather explain how to do it should the need arise.

Read more »

Get filename from URL using Javascript

This snippet will get the filename from the url. The filename is the last part of the URL from the last trailing slash. For example, if the URL is then file.html is the file name.

Read more »

WAMP and Skype Conflict

I have just discovered a conflict between Skype and WampServer that I thought I would share. They both use port 80 which causes the conflict. If you run Skype before running Wamp, then Apache will not run. If you go to a site on localhost, you will probably get a blank screen.

Read more »

Backup MySQL Database from Cron

Backup a database from cron. Add the following to the cron tab.

date=`/bin/date "+\%Y-\%m-\%d-\%H-\%M-\%S"` ; cd /home/[USERNAME]/public_html;  mysqldump -u [DATABASE USERNAME] -p[PASSWORD] [DATABASE NAME] > /home/[USERNAME]/backups/[DATABASE NAME]backup_$date.sql ; gzip /home/[USERNAME]/backups/[DATABASE NAME]backup_$date.sql
Read more »

User can’t edit a node – Drupal troubleshooting

From time to time a user may not be able to edit a Drupal node and you end up tearing your hair out trying to figure out why. Sometimes the solution is obvious, and sometimes it is not. This post will take you through some of the main reasons for the problem along with suggested solutions.

Read more »

Set up Google Sitemap in Drupal

Google offers the ability for webmasters to submit guideline information to assist its robots in indexing websites. You can even instruct the Google robot to prioritise certain pages. This is called the Google Sitemap and I highly recommend taking advantage of this facility to ensure that Google is indexing all of your web pages.

Read more »

Remove Page Titles from Panels & Views

There may be times when you want to remove a page title from a page, but leave it as the meta title. By default, Drupal will display the node title in the h1 tag. If you take a look at page.tpl.php, you will see it there. In most themes, it will look something like this:

Read more »

Redirect users to the login form if access is denied

Out of the box Drupal will display a simple Access Denied message is a user is trying to access content that they do not have permission to. This is not exactly user friendly. A better solution is to redirect the user to the login form and when the user logs in, redirect them back to the content that they want to see. There are two main ways to achieve this.

Read more »

Drupal redirect in .htaccess

Using .htaccess is one of the best ways to redirect a URL to a new URL. Particular care needs to be taken with Drupal sites for it to work correctly.

Read more »

Preventing the White Screen in Drupal

If you are using Drupal on share hosting, you have probably experienced a white screen. You see nothing on the screen. You had might as well be skiing in a blizzard. This generally happens when PHP runs out of memory and is one of the biggest problems with shared hosting.

Read more »

Node relativity view children in parent node

You can use node relativity to attach nodes to other nodes. In this case, I am using it to attach reviews to product nodes, where the reviews are nodes in their own right. I want to be able to view the reviews (children) within the product node (parent).

Read more »

PHP max_execution_time error with Drupal and XAMPP

I recently had a problem where PHP was timing out at 60 seconds when running a Drupal site using XAMPP on Windows (yeah I know, Windows and XAMPP sucks). I tried changing my php.ini file to 240 seconds, but it made no difference, it would still time out at 60 seconds. Here are the steps I made to fix this issue.

Read more »

Make Drupal SEO Friendly

Drupal does have some SEO holes when used straight out of the box. In this article, I will list the major flaws and how to overcome them.

Duplicate Content

Because of the way the Drupal file system works, it is possible to access the same content with different URL's. This is particular dangerous as search engines do not like duplicate content.

Solution: Use the Robots.txt file to block search engine's from indexing secondary paths to your content. See Using Robots.txt with Drupal to avoid duplicate content for more information.

No Meta Tags

By default, Drupal does not allow you to add meta tags to pages. Description and keyword meta tags are useful in SEO if used correctly.

Solution: Install the Meta Tag module. This will allow you to add description and keyword meta tags to all of your pages.

Trouble indexing all pages

Ok, so this is not a problem confined to just Drupal system. Search engines often have trouble indexing all the pages on a website. This problem is made worse when your content is generated dynamically from a database when using a content management system like Drupal.

Solution: Install XML Sitemaps module. This will create an XML sitemap of all of your pages. You can then submit that sitemap to Google to help its crawlers index your pages. See Set up Google Sitemap in Drupal for more information.

Non descriptive URL's

By default, Drupal creates standard, non-descriptive URL's for each page. Each page is a node and the URL become Some search engines (in particular MSN) like to have keywords in the URL.

Solution: Install the Pathauto module. This will automatically create meaningful URL's. You can base the URL's on factors like date, author, title, and category. I would recommend you use categories and titles. For example: title.

If you are using this module, then you are creating duplicate content. A user and search engine can access your content using node/1 or cat/page-title. So it is really important that you block search engine robots from indexing anything with node in the url. You can do this by adding this to your robots.txt file:

Disallow : /node/*

See Using Robots.txt with Drupal to avoid duplicate content for more information on preventing duplicate content.

When following the above guidelines, Drupal is very search engine friendly. You should enjoy a higher search engine ranking then most other content management systems.

Read more »

Add Edit this node/block link to Drupal View

It is often useful to add a “edit this node” or “edit this block” if a site editor is viewing content on a page that is not the node page itself. This includings viewing content from a “view” page where the normal edit tabs are not present for nodes or blocks.

Read more »

Controlling the Break with Drupal Teasers

One of the core features of Drupal is the teaser functionality. This allows you to show a teaser on the home page and category pages, rather the full article. The user has to click through to the full page to see the article in full. I really like this feature as it makes it a lot easier for user to scan through a range of stories on the home page before deciding which one they want to view in detail.

Read more »

Add new user to MySQL database

Add new user to MySQL database. First, log into the MySQL console, and then run the following command, replacing databasename, username and password.

mysql> GRANT ALL ON databasename.* TO username@localhost IDENTIFIED BY 'password';
Read more »

Restore MySQL database in WampServer

If you are running WampServer on your local machine, it can be a bit tricky to restore a MySQL database. You need to do it from the Windows command line (DOS prompt), rather then the MySQL console command line. The actual MySQL restore command is slightly different to normal and you need to make sure you are in the right directory first.

Read more »

Reset auto increment after deleting a table row

It is often the case that a column such as the ID column on a table will auto increment. This simply means that the next insert into the table will have an ID that is one more then the previous one and therefore all ID’s will be unique.

Read more »

Warning a user when navigating away from a Drupal form without saving

Normal users are not like us. We know that if we leave a page before submitting a form, the data we have added will be lost. Normal users might be happily filling in a web form, get half way through, get distracted and then click on a link and lose their data. Ok, maybe they are exactly like us, because I have done this as well. We are all busy. We all get distracted.

Read more »

Tag nodes from a content type with a taxonomy term

Lets assume that you have a bunch of nodes for a content type and you want to tag them all with the same taxonomy term. First, find the term ID of the relevant term. In example, the term ID is 103 and the content type is “contact”.

Read more »

Should I use a .biz or .info domain?

Should I use a .biz or .info domain? is a common question when trying to decide on a new domain name. Most people agree that .com’s are the daddy’s of domain names. If your target market is within one country, then you might go for a country specific domain name like (UK), .de (Germany), (New Zealand) or (Australia). If you really want an international domain and the .com is not available, you might try a .net or even a .org. But what if none of those are available, but .biz or .info is? Are they too obscure for your new web venture?

Read more »