20th December 2013

Are you a developer new to Drupal? Read this...

John Ennew
Technical Director

Deeson Online present a training plan for a skilled software developer coming to Drupal for the first time.

Drupal Basics

For someone not versed in Drupal at all, the Using Drupal book by O'Reilly is the best place to start. This is particularly true for developers coming from a background in which the construction of a website using web UI tools is not a familiar concept.

Once the tutorials in this book have been covered, the dev should have an excellent grounding of the basics of Drupal and should begin to understand why using the community modules are useful.

Drush

After the unpleasantness of having to use the GUI to make things, you can take a short rest and familiarise yourself with Drush  a command line tool providing a number of useful resources for administering a Drupal site:

Coder and coding standards

Now you need to make sure your code adheres to our coding standards. The Drupal project specifies its own. If you are using PHP Storm IDE (which you really should be) then you can follow this tutorial to set it up correctly:

There is also a Drupal module which checks your code for you. So set this up and have a go:

Writing your first theme

Boostrap and sub-theming

It would then be advisable to look at how theming and sub-theming works with the bootstrap theme which we use here at Deeson Online:

Also, if you are going to be using SASS read this article about how to setup your system for automatically compiling your CSS and JavaScript.

Features

Now, you've created a whole lot of stuff above that only exists in the database.... and you probably feel dirty. If not, what kind of dev are you!?

To get that stuff out of the DB and into code where it can be version controlled in Drupal 7 you need to use an add-on module called Features. Learn how to use this next:

Drupal recognise that things only existing in the database is a problem, so the Features module is an attempt to rectify it but it is far from perfect. (In Drupal 8 this is solved in a whole new way, but that's for another day!)

Must-have modules

There are a number of 'must-have' modules that all projects will have. It would be good to familiarise yourself with these now:

  • pathauto - for setting automatic URL patterns for each content type on the system 
  • navbar - a better toolbar than the one shipped with Drupal.
  • admin_views - replace the standard admin pages in Drupal with ones generated by the views module
  • captcha  - add captcha to forms
  • ckeditor - rich text editing (follow the README file instructions after enabling)
  • date - superior date handling tools, fields and views integration
  • devel - for dev environment  provides development tools. Eg in custom code try dpm($my_variable); or kpr($myvariable) for neat debugging of data
  • email - provides an email field
  • entity - provides superior entity api functions
  • entitycache - provides better caching of entities
  • entityreference - provides a field which allows one entity (eg a node) to reference another.
  • field_group - group fields together on the node edit form in various ways
  • globalredirect - basic redirect rules such as providing a 301 redirect from node/123 to it's aliased version
  • google_analytics - easy integration with Google analytics
  • URL field - provides a link field to easily add a hyperlink to the page
  • masquerade - provides a block which allows the site admin to login as any other user of the site
  • navbar_region - allows blocks to be added into the navbar, really handy for masquerade
  • media - potentially really good media handling (image library etc) for admins to manage their content
  • image field focus - Allows image selection and scaling based on portions of the image, see a tutorial here.
  • module_filter - a better module management screen
  • honeypot - spam protection for forms
  • metatag - seo fields
  • entityqueue - allows nodes to be placed and manually ordered in a queue. The queue can then be used as the basis of a carousel (via a view for example).
  • redirect - allows site admin to create redirects on the site
  • seckit - adds a bunch of best practice security options
  • styleguide - provides an admin page which lists all HTML components in the current site styles, useful when reviewing them
  • views - create listing pages and sql queries in the UI (this is also covered in Using Drupal)
  • webform - a (reasonably) simple way of allowing content editors create questionnaires on the site

Writing your first module

Congratulations  you are now ready to write a module! The following tutorial will help with this:

What not to do

The fail module is an excellent piece of code to study as it gives a lot of commented examples of 'worst practice' in Drupal. Add it to a Drupal site with 'drush dl fail'

What to do

The examples in contrib project contain a whole load of modules which demonstrate how to use various components of the Drupal eco-system in code.

Almost all these are worth studying except entity_example unless you are feeling masochistic (the eck module provides this functionality in an easier to digest form).

The Path to Live

As a developer you will be working with a development version of a site and only making changes on the live site by deploying code. We've already introduced the features module for this, but here are a list of others that will help you as well:

  • entityform - Webform mentioned in Must Have modules above is great for content editors to make arbitary forms on their site, but developers should be using entityform so that forms can be created once on the development site, committed to code using features and deployed to live in one switft movement.
  • master - this module allows a module dependency listing per environment (dev, test, live). You can then script some of its drush commands to ensure the correct modules are enabled or disabled on each environment
  • strongarm - allows variables in the variable table to be exported via features
  • reroute_email - stops development sites sending emails to real users

Advanced concepts

If you still want more, take a look at the following modules that will help in creating more complex sites:

  • context - allows functionality on the site to be determined by 'context' ie where the user is and what they are doing
  • paragraphs - Allows more flexible content editing by constructing a simple brochure type page out of several sub components reasonably easily.
  • panels - Allows even more flexible content editing but with a much more complex interface
  • rules - allows events, conditions and actions on the site (for people who can't write code)
  • commerce - a superb e-commerce framework which is built with Drupal. The commerce kickstart distribution demonstrates its abilities superbly
  • eck - The entity construction kit allows the construction of entities. Entities exist on the same level as node or taxonomy. These are data containers
  • migrate - This is a developer's tool used for data migrations into Drupal
  • wsif - This is a developer tool providing a best practice framework for developing web service integrations into Drupal
  • group - For creating access controlled areas of your site or sub sites. See also Organic Groups but we think group is better.
  • drupalextension - Not actually a Drupal module, this plugs into the behat framework to let you write functional tests for your site

Other books

Some other useful books are:

So there you go. Get cracking - and tell us how you get on!