Creating Your Own Recipe
Drupal recipes provide a standardized way to package and apply sets of modules, configurations, and permissions as reusable, composable units. This guide explains how to create a custom recipe that builds on Varbase to add project-specific functionality.
Recipe Structure
A Drupal recipe is a directory containing a recipe.yml file and optionally a config/ directory with configuration files. The basic structure is:
my_custom_recipe/
recipe.yml
config/
module_name.config_name.yml
another_module.another_config.ymlCreating the recipe.yml File
The recipe.yml file is the core of every recipe. It defines the recipe's metadata, dependencies, modules, configuration actions, and permissions.
Basic Structure
name: 'My Custom Recipe'
description: 'A custom recipe that adds project-specific functionality to a Varbase site.'
type: 'Site'Defining Dependencies
Dependencies declare other recipes that must be applied before this recipe:
When your recipe is applied, all dependency recipes are applied first in the order listed.
Installing Modules
Specify modules that should be installed by the recipe:
Configuration Actions
Config actions allow you to modify existing configuration or create new configuration:
Setting Permissions
Grant permissions to specific roles:
Including Configuration Files
To include full configuration files, place them in the config/ directory within your recipe. These files follow the same naming convention as Drupal configuration exports:
Each configuration file contains the full YAML configuration for that config item. You can export existing configuration using Drush:
Then copy the relevant files to your recipe's config/ directory.
Complete Example
Here is a complete example of a custom recipe that adds a "Project" content type:
With the corresponding configuration files in the config/ directory defining the content type, fields, view displays, and form displays.
Applying Your Recipe
To apply your custom recipe using Drush:
For Recipes in the Project Directory
Place your recipe in the recipes/ folder of your Varbase project, next to the Varbase recipes, then apply it:
For Recipes Installed via Composer
If your recipe is published as a Composer package of type drupal-recipe, require it and Drupal core's Recipe Unpack plugin will unpack it into the recipes/ folder, adding its dependencies to your project's composer.json. Then apply it:
Publishing Your Recipe
To make your recipe available to others:
Create a project on Drupal.org.
Publish the recipe as a Composer package.
Others can then install it via Composer and apply it with Drush.
Best Practices
Keep recipes focused: Each recipe should address a single area of functionality. Compose larger configurations from multiple smaller recipes.
Declare dependencies explicitly: List all recipe dependencies so that applying your recipe automatically satisfies all requirements.
Use config actions over raw config: Prefer
createIfNotExistsandgrantPermissionsconfig actions over raw configuration files when possible, as they are more resilient to existing site state.Test recipe application: Test your recipe on a clean Varbase installation to ensure it applies without errors.
Document your recipe: Include a clear description and any special instructions in the
recipe.ymlfile.
Last updated