Theming
Topic

Drupal Coding Standards for Drupal 7, 8, 9, and 10

The Drupal community has defined a set of coding standards and best practices that you should adhere to whenever you're writing code for Drupal. These standards provide a set of rules for how your code should be formatted, and best practice guidelines for naming conventions and the location of files. This ensures consistency in code throughout the project and makes it easy for developers to move around from one sub-section to another without having to re-learn how to read the code.

Example tasks

  • Know where to find formatting standards for PHP, CSS, JavaScript and HTML in Drupal
  • Automate coding standards compliance for code
  • Properly use the t() function to make strings translatable in code

Confidence

This is a well-defined area that does not tend to change quickly or dramatically.

Drupalize.Me resources

Categories
Drupal 8, 9, and 10
More information

ESLint is the linting tool of choice for JavaScript in Drupal. In this tutorial we’ll show how to install the ESLint application and then use it to verify that your JavaScript files are meeting the Drupal coding standards.

Drupal (as of version 8.4) has adopted the Airbnb JavaScript coding standards. In this tutorial, we'll walk through how to install the necessary package dependencies to run eslint on JavaScript files within your Drupal site.

Guides

Not sure where to start? Our guides provide useful learning tracks for all skill levels.

Navigate guides

External resources