In this lesson, we will delve into Drupal's directory structure, a fundamental aspect for any website developer working within the Drupal ecosystem. Understanding these directories, including modules, themes, and sites, is crucial for managing your projects effectively and customizing your Drupal installation.
Understanding the Drupal Directory Structure
Drupal's file system is organized to separate core functionality from customized and third-party additions. This structure maintains site integrity during updates and facilitates site flexibility. Let's break down the key directories within a standard Drupal installation.
/core
The /core
directory contains all of Drupal's core files. This includes essential modules, themes, libraries, and files necessary for the functioning of Drupal. You should avoid modifying these files as any changes may be overwritten during an update. Instead, extend functionality through contributed and custom modules and themes.
/modules
The /modules
directory is designated for non-core modules. Organizing this directory properly is important for maintaining clarity between third-party and custom contributions:
- /modules/contrib: Store all contributed modules downloaded from Drupal.org here.
- /modules/custom: This folder is for custom modules developed specifically for the site.
/themes
The /themes
directory parallels the /modules
directory but is specific to themes:
- /themes/contrib: Houses all third-party themes used by the site.
- /themes/custom: Contains custom-designed themes tailored to your site's branding and design specifications.
/profiles
The /profiles
directory is used for installing different Drupal distributions, which may already have configurations, modules, and themes pre-installed to jump-start your site development.
Navigating the /sites Directory
The /sites
directory is critical for managing site configurations, especially in multisite installations, which use a single Drupal codebase to run multiple sites.
/sites/default
This is the typical configuration directory for a singular Drupal site. Within /sites/default
, you'll find files such as:
- settings.php: Contains all key configuration settings, including database connection details.
- services.yml: Handles service configurations like caching and platform optimization settings.
/sites/all (Deprecated)
Historically, /sites/all
was used to store themes, modules, and libraries shared across all sites in a multisite setup. However, using /modules
and /themes
directories for this purpose is now the recommended practice.
Multisite Configurations
Drupal's multisite capability is a standout feature for those managing several sites. You can set up separate configuration directories for each site, each named according to its domain (e.g., /sites/site1.com
), with its own settings.php
and other configuration files to manage site-specific configurations.
Managing Module and Theme Directories
Proper management of module and theme directories is vital for maintaining a clean and efficient Drupal environment. Let's explore best practices:
Installing Contributed Modules and Themes
Whenever you download a module or theme from Drupal.org, place it in the appropriate /contrib
directory:
- Download from the module or theme page on Drupal.org.
- Extract the downloaded files and move them to
/modules/contrib
or/themes/contrib
. - Ensure file permissions are correct to avoid access issues when enabling them in Drupal.
Developing Custom Modules and Themes
For custom development, use the /custom
subdirectories:
- Module Development: Create a unique directory under
/modules/custom
with necessary subdirectories for assets such as CSS, JS, and template files. - Theme Development: Your custom theme under
/themes/custom
should include directories for templates, CSS, JS, and other assets, maintaining a clear structure.
Benefits of an Organized Directory Structure
A well-managed directory structure offers several advantages:
- Ease of Maintenance: Clearly separated directories simplify updates and management tasks for modules and themes.
- Improved Collaboration: Teams can easily locate and understand the project's structure, which facilitates better collaboration and handover.
- Enhanced Security: If a module or theme requires updates or removal, a well-organized structure minimizes the risk of accidental deletions or misconfigurations.
Conclusion
Understanding and navigating the Drupal directory structure is essential for maintaining a clean, efficient, and scalable website. With organized directories for modules, themes, and site-specific configurations, you simplify site management and pave the way for smooth updates and maintenance.