Skip to main content

Drupal Recipes System Comprehensive Guide

Overview​

Drupal Recipes represent a fundamental shift in how Drupal sites are configured and deployed. Unlike traditional modules that are installed/uninstalled, recipes are applied once to configure existing Drupal installations, making them ideal for enterprise deployment strategies.

What Are Drupal Recipes?​

Core Concept​

Recipes automate module installation and configuration by creating scripts that can:

  • Install modules and themes
  • Apply configuration settings
  • Set up default content
  • Configure workflows and permissions
  • Establish content types and fields

Key Differentiators from Modules​

  • Not Installed: Recipes are applied, not installed
  • One-Time Application: Applied once, then removed
  • Configuration Focus: Primarily handles configuration, not ongoing functionality
  • Deployment Tool: Designed for site setup and feature deployment

Technical Architecture​

Core APIs (Drupal 10.3+)​

Recipe API (Drupal\Core\Recipe)​

<?php
// Basic recipe structure
class RecipeManager {
public function applyRecipe(string $recipe_path): RecipeApplicationResult {
$recipe = Recipe::createFromDirectory($recipe_path);

// Validate recipe dependencies
$this->validateDependencies($recipe);

// Apply recipe components
$this->installModules($recipe->getModules());
$this->applyConfiguration($recipe->getConfiguration());
$this->createDefaultContent($recipe->getDefaultContent());

return new RecipeApplicationResult($recipe);
}
}

Config Action API (Drupal\Core\Config\Action)​

<?php
// Dynamic configuration modification
class ConfigActionManager {
public function executeActions(array $actions): void {
foreach ($actions as $action) {
$this->configActionExecutor->execute(
$action['plugin'],
$action['config'],
$action['data']
);
}
}
}

Checkpoint API (Drupal\Core\Config\Checkpoint)​

<?php
// Configuration snapshots and rollback
class CheckpointManager {
public function createCheckpoint(string $label): CheckpointInterface {
return $this->checkpointStorage->create([
'label' => $label,
'timestamp' => time(),
'configuration' => $this->exportCurrentConfig()
]);
}

public function rollbackToCheckpoint(CheckpointInterface $checkpoint): void {
$this->configImporter->importFromCheckpoint($checkpoint);
}
}

Default Content API (Drupal\Core\DefaultContent)​

<?php
// YAML-based content provisioning
class DefaultContentManager {
public function importContent(string $content_path): void {
$content_files = $this->scanner->scan($content_path, '*.yml');

foreach ($content_files as $file) {
$content_data = Yaml::decode(file_get_contents($file));
$this->createEntity($content_data);
}
}
}

Recipe Structure​

Standard Recipe Directory Layout​

my_recipe/
β”œβ”€β”€ recipe.yml # Recipe metadata and dependencies
β”œβ”€β”€ composer.json # Composer dependencies
β”œβ”€β”€ config/
β”‚ β”œβ”€β”€ install/ # Configuration to install
β”‚ β”‚ β”œβ”€β”€ core.entity_form_display.node.article.default.yml
β”‚ β”‚ └── core.entity_view_display.node.article.default.yml
β”‚ └── optional/ # Optional configuration
β”‚ └── views.view.content.yml
β”œβ”€β”€ content/ # Default content (YAML format)
β”‚ β”œβ”€β”€ node/
β”‚ β”‚ └── article.yml
β”‚ └── user/
β”‚ └── admin.yml
└── modules/ # Custom modules (if needed)
└── custom_feature/

Recipe Metadata (recipe.yml)​

name: 'Enterprise Content Management'
description: 'Complete content management setup for government agencies'
type: 'Site'
recipes:
- 'core/recipes/standard'
- 'contrib/recipes/workflow'
install:
- node
- taxonomy
- workflows
- content_moderation
- pathauto
config:
actions:
user.settings:
simpleAction:
- 'set user_register to visitors_admin_approval'
workflows.workflow.editorial:
createIfNotExists:
langcode: en
status: true
dependencies: {}
id: editorial
label: Editorial
type: content_moderation

Advanced Configuration Actions​

# Complex configuration modifications
config:
actions:
# Create content type if it doesn't exist
node.type.policy_document:
createIfNotExists:
type: policy_document
name: 'Policy Document'
description: 'Official government policy documents'
settings:
node:
preview_mode: 1
display_submitted: false

# Configure field storage
field.storage.node.field_classification:
simpleAction:
- 'set field_type to list_string'
- 'set settings.allowed_values to {public: Public, classified: Classified, secret: Secret}'

# Set up permissions
user.role.content_editor:
grantPermissions:
- 'create policy_document content'
- 'edit own policy_document content'
- 'use editorial transition create_new_draft'

Enterprise Recipe Development​

Government Compliance Recipe​

name: 'Government Compliance Suite'
description: 'FISMA and Section 508 compliance configuration'
type: 'Feature'
install:
- gov_compliance
- accessibility_checker
- audit_trail
- encrypt
- key
config:
actions:
gov_compliance.settings:
simpleAction:
- 'set fisma_level to moderate'
- 'set audit_logging to true'
- 'set encryption_required to true'

encrypt.profile.government:
createIfNotExists:
id: government
label: 'Government Encryption'
encryption_method: 'real_aes'
key_provider: 'file'

AI Platform Integration Recipe​

name: 'LLM Platform Integration'
description: 'Complete AI integration for government agencies'
type: 'Site'
recipes:
- 'recipes/government_compliance'
install:
- llm
- ai_provider_ollama
- mcp_registry
- alternative_services
- api_normalizer
config:
actions:
llm.settings:
simpleAction:
- 'set default_provider to ollama'
- 'set ollama_endpoint to http://localhost:11434'
- 'set enable_audit_logging to true'

ai_provider_ollama.settings:
simpleAction:
- 'set default_model to llama3.2:7b'
- 'set timeout to 30'
- 'set max_tokens to 4096'

Enterprise Deployment Strategies​

Multi-Environment Recipe Strategy​

#!/bin/bash
# Enterprise deployment script

# Development environment
drush recipe:apply recipes/base_platform
drush recipe:apply recipes/development_tools

# Staging environment
drush recipe:apply recipes/base_platform
drush recipe:apply recipes/staging_config
drush recipe:apply recipes/performance_monitoring

# Production environment
drush recipe:apply recipes/base_platform
drush recipe:apply recipes/production_config
drush recipe:apply recipes/security_hardening
drush recipe:apply recipes/government_compliance

Continuous Integration Recipe Pipeline​

# .gitlab-ci.yml
stages:
- validate
- test
- deploy

validate_recipes:
stage: validate
script:
- drush recipe:validate recipes/government_platform
- drush recipe:validate recipes/security_hardening

test_recipe_application:
stage: test
script:
- ddev start
- drush si minimal -y
- drush recipe:apply recipes/government_platform
- drush pm:enable -y simpletest
- drush test-run --all

deploy_to_staging:
stage: deploy
script:
- drush @staging recipe:apply recipes/government_platform
- drush @staging cr
only:
- main

Recipe Management Tools​

Recipe Generator Integration​

# Interactive recipe creation
drush recipe:generate

# Output structure:
# What is the recipe name? Government AI Platform
# What is the recipe description? Complete AI integration for government
# What type of recipe is this? [Site/Feature] Site
# Which modules should be installed? llm, ai_provider_ollama, mcp_registry
# Generate default content? [y/N] y

Custom Recipe Generation Script​

<?php
// Custom recipe generator for enterprise patterns
class EnterpriseRecipeGenerator {
public function generateGovernmentRecipe(array $options): string {
$recipe_data = [
'name' => $options['name'],
'description' => $options['description'],
'type' => 'Site',
'install' => $this->getGovernmentModules($options),
'config' => [
'actions' => $this->generateGovernmentConfig($options)
]
];

return Yaml::encode($recipe_data);
}

private function getGovernmentModules(array $options): array {
$base_modules = ['gov_compliance', 'audit_trail', 'encrypt'];

if ($options['ai_enabled']) {
$base_modules = array_merge($base_modules, [
'llm', 'ai_provider_ollama', 'mcp_registry'
]);
}

return $base_modules;
}
}

Security & Compliance Considerations​

Recipe Security Best Practices​

  1. Configuration Validation: Validate all configuration before application
  2. Dependency Checking: Verify all dependencies are secure and up-to-date
  3. Permission Auditing: Review all permission changes in recipes
  4. Content Sanitization: Sanitize all default content

Government Deployment Considerations​

# Security-focused recipe configuration
name: 'Secure Government Platform'
config:
actions:
system.site:
simpleAction:
- 'set page.403 to /access-denied'
- 'set page.404 to /page-not-found'
- 'set admin_compact_mode to true'

user.settings:
simpleAction:
- 'set password_strength to true'
- 'set password_reset_timeout to 86400'
- 'set user_register to admin_only'

system.performance:
simpleAction:
- 'set cache.page.max_age to 0' # Disable caching for secure sites
- 'set response.gzip to false' # Disable compression for secure sites

Integration with LLM Platform​

AI-Enabled Recipe Templates​

# LLM Platform recipe with AI providers
name: 'AI-Powered Government Platform'
install:
- llm
- ai_provider_ollama
- ai_provider_anthropic
- mcp_registry
- alternative_services
config:
actions:
llm.provider.ollama:
createIfNotExists:
plugin: ollama
label: 'Local Ollama'
configuration:
endpoint: 'http://localhost:11434'
default_model: 'llama3.2:7b'
timeout: 30

mcp_registry.server.platform:
createIfNotExists:
name: 'LLM Platform Server'
transport: 'stdio'
command: 'node'
args: ['/path/to/mcp-server.js']

Best Practices & Recommendations​

Recipe Development Guidelines​

  1. Modular Design: Create focused, single-purpose recipes
  2. Dependency Management: Clearly define all dependencies
  3. Version Control: Tag and version recipes for reproducibility
  4. Testing: Comprehensive testing on clean Drupal installations
  5. Documentation: Document all configuration changes

Enterprise Recipe Strategy​

  1. Base Platform Recipe: Core configuration for all sites
  2. Feature Recipes: Specific functionality (AI, compliance, etc.)
  3. Environment Recipes: Environment-specific configurations
  4. Custom Recipes: Organization-specific customizations

Performance Considerations​

  • Use checkpoints for large recipe applications
  • Apply recipes during maintenance windows
  • Monitor resource usage during application
  • Implement rollback procedures for failed applications

Drupal Recipes provide a powerful deployment strategy for enterprise Drupal applications, enabling consistent, repeatable site configurations that align with government and defense requirements.