Blair Wadman 3 minute read

Drupal Code structure

Drupal’s code is split into three main areas: core, contributed and custom.

Drupal Core

When you download Drupal, you are downloading Drupal core. It consists of a set of library files, core modules, Symfony components and more. It is relatively lean and provides the base level of functionality needed to build a basic website.

As a general rule, you should not alter the core code. In Drupal, if you want to add functionality, or change the way Drupal behaves, you do this either by downloading a contributed module or creating your own custom module.

One of the key differences with Drupal 8 is that it includes a lot more functionality in core than previous versions.

Contributed Projects

Drupal core is extended via contributed modules and themes. There are thousands of modules on drupal.org and they offer a huge variety in extra functionality. Contributed modules are developed by Drupal developers who are “contributing” back to the community. They maintain, develop further and deal with the issue queues on a voluntary basis. This forms an important part of the essence of the Drupal community.

As is the case with any new release of Drupal, some of the contributed modules that exist for Drupal 7 are not yet available for Drupal 8. Many are in the process of being upgraded and you might find dev versions of many of them. You can use the dev version of a module but it does carry more risk because it is not yet stable.

Custom Modules

A custom module is a module that you (or your team) have developed yourself. It may become a contributed module if you make it generic enough so that it is not tied to your specific instance of Drupal.

Drupal Structure

The file structure has changed a lot from Drupal 7 to Drupal 8.

In Drupal 7, core modules go in the modules folder in the root of the Drupal installation. Contributed modules and custom modules go in the sites/all/modules folder (or if you are running a multi site, sites/sitename/modules)

In Drupal 8, core modules can be found in core/modules. This frees up the modules folder in the root of the Drupal installation for your contributed and custom modules.

Theme system

The Theme System controls the display and presentation (look and feel) of content. The theme system is not confined to just themes. Core libraries, modules and themes all make up the theme system. The core library initialises themes and locates theme functions and templates to use. Modules can define default theming for the content that it is responsible for. A theme can then override that theming.

Drupal 7 themes were based on the PHPTemplate engine. Drupal 8 is based on Twig. This makes it easier for frontend developers and designers because you will no longer need to touch any PHP when working with Drupal themes.