Skip to main content

Drupal 8 Now: Writing Drupal 7 code with an eye towards Drupal 8

We're getting closer to that difficult stage. You know, that point where we're nearing a new major Drupal release. That point where customers with flexible delivery dates who are thinking about starting a new project are asking if they should wait for Drupal 8 to come out or build on Drupal 7.

Those of us who went through the Drupal 6 and Drupal 7 release know what I'm talking about. Do I build it on Drupal 6 or do I chance it on Drupal 7 and work through any missing modules.

We're not there yet for Drupal 8, but we already have customers asking us to develop Drupal 7 sites in a fashion sympathetic to Drupal 8.

So what does that mean? Well we have a few pointers on starting new Drupal 7 modules that will be easier to upgrade to Drupal 8 when the time comes. We'll present these in a new Drupal 8 Now! series of blog posts.

by lee.rowlands /

The posts

Over the coming weeks we'll post the following Drupal 8 Now articles:

  • Part 1 - PSR-0 in Drupal 7In this article I'll present how you can start using PSR-0 namespaced code in your Drupal 7 modules
  • Part 2 - Object Oriented Page callbacks in Drupal 7 In this article @xtfer will demonstrate using object oriented controllers in Drupal 7 for page callbacks.
  • Part 3 - Object Oriented plugins in Drupal 7In this article I'll present object-oriented plugins for Drupal 7
  • Part 4 - Composer dependencies in Drupal 7In this article @kim.pepper will demonstrate how to use composer dependencies in Drupal 7, using the Guzzle library (as used in Drupal 8) as an example.
  • Part 5 - PHPUnit tests in Drupal 7In this article I'll present a technique for adding unit-tests in Drupal 7
  • Part 6 - Injecting database connectionsIn this article I'll present a technique for injecting the active database connection into your object-oriented Drupal 7 code allowing you to write decoupled code, ready for porting to Drupal 8's architecture.


We hope you enjoy this series as much as our Drupal 8 ready series.

Posted by lee.rowlands
Senior Developer



Comment by dawehner



Comment by netsensei


Looking forward! :-)

Comment by odegard


Great, looking forward to them!

Comment by fubhy


Cool! Looking forward to reading those! We are doing the same for all our projects for nearly a year now and it's definitely proven itself worthy. I am interested in seeing what your approach is. :)

Comment by mrsinguyen


Looking forward to this. Can't wait. :D

Comment by donquixote


Somehow related to the series: I often create some kind of poor man's service container for contrib modules.
This makes it easier to write classes that don't call into some global state. E.g., xautoload has all the Drupal-related stuff factored out int a DrupalSystem object, which can be replaced for unit testing.
The container implementation in xautoload and Crumbs is maybe not the nicest to look at, but this is the general idea:…

This is not really formally D8-style, but philosophically..