Understanding the Drupal Way - Basic Drupal Principles

Submitted by Marc on Wed, 12/02/2015 - 6:12pm

The first thing to understand about Drupal is that it is based on a modular approach to providing functionality. I will elaborate on this further in another post.

The point I want to focus on in this post is that every module on a Drupal site is a first-class citizen. There are no "special" modules that can so something that other modules cannot do.

Three basic types of modules are:

  1. core
  2. contrib
  3. custom

Core modules are what is included with Drupal when you download the archive file from Drupal.org.

Contrib modules are those that have been contributed by members of the community and that can optionally be downloaded and used. You can find contrib modules at Download & Extend.

When you choose a particular contributed module to download one of the first things you should notice is that the namespace for that module is structured in the same way as the namespace for Drupal core. That is to say, the module will be located at https://www.drupal.org/project/[project-shortname]

Custom modules are any modules that are installed on a Drupal site that are not included on Drupal's official site.

When you need to add new functionality to a Drupal site, you may enable another core module, download and enable a contrib module or write a custom module on your own.

What you should never do is hack core or contrib.

This is the first rule of Drupal: Don't Hack Core!

Some people may think that this rule is on account of the "elite" being persnickety about other people touching their code. The reality is that the rule is in place for your own benefit.

I'll give you an example right now of why you don't want to hack core. Let's say that you wanted to tweak the way the Bartik theme appears. You decided to modify the page.tpl.php file located inside of themes/bartik/templates. Once you did it, everything looked great to you. But, wait until you update Drupal. If you use a tool like drush, then all your changes will be lost. If you update manually, you'll have to remember to re-implement your hacks.

The second rule of Drupal is: Modules and themes should be placed in the appropriate place in the directory structure.

For Drupal 7 and below, that means placing them somewhere inside of the sites directory. This was a point of confusion for many people who are new to Drupal. The modules and themes directories seemed like a logical place to put things. However, those directories hold the core code. Starting with Drupal 8, this confusion has been addressed. There is a core directory under which all core code resides. It's okay to place modules and themes inside of the modules and themes directories in Drupal 8. It's also still possible to place them somewhere within the sites directory.

So, you may be wondering how you should have customized the Bartik theme on your site. I'll explain that in another post!

If you'd like to learn more about Drupal, you can take my course "Drupal for Beginners" for just $5.