Overriding Varbase
There are situations where you need to change Varbase's default behavior or configuration without modifying the original recipes or contributed modules. Drupal provides several mechanisms for overriding configurations and behaviors, all of which work with Varbase.
Configuration Overrides in settings.php
Drupal's configuration override system allows you to change any configuration value through settings.php without modifying the stored configuration. These overrides take precedence over the database configuration and are not exported with drush config:export.
Basic Configuration Override
Add overrides to your settings.php or settings.local.php file:
// Override the site name
$config['system.site']['name'] = 'My Custom Site';
// Override the site email
$config['system.site']['mail'] = 'admin@example.com';
// Override a specific module setting
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;Environment-Specific Overrides
Use configuration overrides to set different values for different environments:
Disabling Modules via Configuration
You can override module-specific settings to effectively disable certain behaviors:
Custom Modules
For more complex overrides that cannot be achieved through configuration alone, create a custom module.
Creating a Custom Module
Create a minimal module structure:
The my_overrides.info.yml file:
Using Hooks
Hooks allow you to alter Drupal's behavior at specific points in the request lifecycle.
Alter Forms
Alter Views
Alter Entity Access
Using Event Subscribers
For Symfony-based event handling, create an event subscriber service:
my_overrides.services.yml:
src/EventSubscriber/MyOverridesSubscriber.php:
Theme Overrides
Override Varbase theme templates and styles through your custom sub-theme. See Creating Your Own Theme for details.
Twig Template Overrides
Copy templates from Varbase modules or the Vartheme BS5 theme into your sub-theme's templates/ directory and modify them. Drupal automatically uses the most specific template available.
Preprocess Functions
Add preprocess functions in your theme's .theme file:
Overriding ECA Workflows
ECA workflows provided by Varbase recipes can be modified through the ECA modeler interface at Configuration > Workflow > ECA. You can:
Disable workflows you do not need.
Modify existing workflows to change conditions or actions.
Clone a workflow and customize the copy.
Best Practices
Use the lightest touch possible: Start with configuration overrides in
settings.php. Only create custom modules when configuration overrides are insufficient.Never modify contributed code: Always use hooks, events, or configuration overrides instead of modifying Varbase recipes, contributed modules, or Drupal core directly.
Document all overrides: Keep clear records of what has been overridden and why, so future developers can understand the project-specific changes.
Test overrides during updates: After updating Varbase or its dependencies, verify that your overrides still work correctly with the new versions.
Keep custom modules minimal: Place only override-specific code in your custom modules. Avoid duplicating functionality that Varbase already provides.
Last updated