Coding standards

The Drupal Coding Standards apply to code within Drupal and its contributed modules.

Coding standards

The Drupal Coding Standards apply to code within Drupal and its contributed modules.

API documentation and comment standards

How to write documentation that can be parsed by the API module, Drupal project standards for API documentation and comments in PHP code

API Documentation Samples

This page is intended to be a collection of the complete API documentation examples


CSS coding standards and best practices.


JavaScript coding standards and best practices for Drupal.

Markdown coding standards

This is currently being discussed in [#2191525].


PHP 5.3 introduces namespaces to the language. This page documents how namespaces should be referenced within Drupal and it assumes that

Naming standards for Services and extending Symfony

Elements added to the Request attributes should have a _ prepended unless they come from the path

Object-oriented code

Drupal follows common PHP conventions for object-oriented code, and established industry best practices. As always, though, there are

PHP Exceptions

Basic conventions, exception subclasses, try-catch blocks, inheritance

PSR-4 namespaces and autoloading in Drupal 8

Summary of how Drupal 8 uses the PSR-4 standard for namespace autoloading

SQL coding conventions

Reserved Words, capitalisation and user-supplied data, naming, configuring DB server for standards compliance

Avoid "SELECT * FROM ..."

Using SELECT * FROM {node} queries in versions prior to Drupal 7 can introduce a potential security issue by causing Drupal's Node Access

List of SQL reserved words

The list below represents a combination of the following sources of SQL reserved words:

Temporary placeholders and delimiters

Temporary place-holders and delimiters

Twig coding standards

The majority of Twig coding standards can be found on the Twig website along with Twig documentation. Items on this page (below) are useful

Use Drupal Unicode functions for strings

If you are writing a module or theme, consider that it may be used on web sites around the world, some of which use languages whose

Write E_ALL compliant code

Adjusting the error reporting level

Drupal SimpleTest coding standards

You should follow these conventions when writing a test.

Drupal Markup Style Guide

The Drupal Markup Style Guide is a document in progress on how to:

Configuration file coding standards

Standards related to configuration files in Drupal 8.

Composer package naming conventions

This is WIP documentation for [#2401519].

Guide maintainers