
The Drupal database layer is built on top of the PHP PDO library. PDO provides a unified, object-oriented API for accessing various databases, but it does not offer abstraction for the different SQL dialects used by different database systems.


The primary way to define a database connection in Drupal is through the $databases
array in settings.php
. As the name suggests, $databases
allows you to define multiple database connections. It also supports defining multiple targets. A connection to the database is not opened (i.e., the connection object is not created) until the first piece of code attempts to run a query against that database.
Connection Key


Interaction with the database should be done through the database connection object. There are several scenarios that require attention:
1. In procedural code, i.e., *.module, *.inc, or script files:
The best way to instantiate the database connection object is via the Service Container.
Example:


The most common SELECT queries in Drupal are static queries using the query() method of the database connection object.
Static queries are passed to the database almost verbatim.
Example:


To create a Drupal 8 theme, you must first create a THEMENAME.info.yml file that provides metadata about your theme in Drupal. This is similar to how modules and installation profiles are defined, so it's important to set the "type" key in the file.info.yml as "theme" to differentiate it.
This page contains an example of a THEMENAME.info.yml file and an overview of the information it may contain.



Translation of the official documentation from Drupal.org. Authors are listed under each article.


A theme is a collection of files that define the presentation layer. You can also create one or more "sub-themes" or theme variations. Only a .info.yml file is required, but most themes and sub-themes will use additional files. This page lists the files and folders found in a typical theme or sub-theme.
Theme Location
You should place themes in the "themes" folder of your Drupal installation. Note that core Drupal themes like Bartik and Seven are located in the core/themes folder of your installation.


Adding regions to your theme requires:
- Adding region metadata in the
THEMENAME.info.yml
file. - Editing the
page.html.twig
file and printing the new regions.
Note: If you declare any regions in your theme—even just one—the default regions will no longer apply, and you are responsible for declaring all the regions you intend to use.


This documentation is for themes. For information about modules, see Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 module.
In Drupal 8, stylesheets (CSS) and JavaScript (JS) are loaded using the same system for both modules (code) and themes: asset libraries.
For clarity, these instructions are intended ONLY for working in themes and do not apply to modules.
