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 Drupal Developer

Dated

Comments

Comment by odegard

Dated

Great, looking forward to them!

Comment by fubhy

Dated

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

Dated

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

Comment by Andy Truong

Dated

Hi, I tried to make some D8 API for Drupal 7:

- Autoload: http://v3k.net/en/at_base/autoloader
- Service container: http://v3k.net/en/at_base/di
- Cache tagging: http://v3k.net/en/node/97
- YAML config: http://v3k.net/en/at_base/config
- Kint integration (devel 8.x): http://v3k.net/en/node/117
- YAML routing: http://v3k.net/en/at_base/routing
- Twig template:
- http://v3k.net/en/at_base/twig
- http://v3k.net/en/at_base/entity-template
- And more (:

Comment by donquixote

Dated

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:
http://dqxtech.net/blog/2014-06-13/simple-do-it-yourself-php-service-co…

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

Pagination

Add new comment

Restricted HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <h5> <h6>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Not sure where to start? Try typing "hello" or "help" if you get stuck.