oveleon/contao-theme-manager-bridge
Bridge package for integrating the Contao Theme Manager with other systems. Adds compatibility glue so themes and Theme Manager features can work smoothly in a bridged setup, simplifying installation, updates, and runtime interactions.
Install the Package Add the package via Composer in your Laravel/Contao project:
composer require oveleon/contao-theme-manager-bridge
Ensure your project uses Contao 4.11+ (or a compatible version) and Symfony 5.4+ (if leveraging Symfony components).
Register the Service Provider
In config/app.php, add the bridge provider to the providers array:
Oveleon\ThemeManagerBridge\ThemeManagerBridgeServiceProvider::class,
Publish Configuration (Optional) Publish the default config to customize behavior:
php artisan vendor:publish --provider="Oveleon\ThemeManagerBridge\ThemeManagerBridgeServiceProvider" --tag="config"
This generates config/theme-manager-bridge.php.
First Use Case: Theme Activation Use the bridge to activate a theme via Contao’s CLI or a custom command:
php contao:theme:activate my-theme-package
Or programmatically:
use Oveleon\ThemeManagerBridge\Facades\ThemeManagerBridge;
ThemeManagerBridge::activateTheme('my-theme-package');
Structure Your Themes
Organize themes as Composer packages in vendor/ or a themes/ directory (e.g., themes/my-theme/). Each theme should:
composer.json with a type: contao-theme.Resources/ directory (e.g., Resources/public/).Autoload Theme Assets Use the bridge to auto-register theme assets in Laravel’s asset pipeline:
// In a service provider or bootstrap file
$bridge = app(Oveleon\ThemeManagerBridge\ThemeManagerBridge::class);
$bridge->registerThemeAssets('my-theme-package', [
'css' => ['Resources/public/css/style.css'],
'js' => ['Resources/public/js/script.js'],
]);
Dynamic Theme Switching Integrate with Laravel’s routing or middleware to switch themes:
// Example: Middleware to set theme based on request
public function handle($request, Closure $next) {
$theme = ThemeManagerBridge::getActiveTheme();
app()->bind('theme', fn() => $theme);
return $next($request);
}
Hook into Contao Events Extend Contao’s theme lifecycle with Laravel events:
// Listen for theme activation/deactivation
event(new ThemeActivated($themeName));
Register listeners in EventServiceProvider:
protected $listen = [
\Oveleon\ThemeManagerBridge\Events\ThemeActivated::class => [
\App\Listeners\LogThemeActivation::class,
],
];
Deployment Automation
Use Laravel’s artisan commands to sync themes during deployment:
php artisan theme-manager-bridge:sync
This updates symlinks, clears caches, and ensures assets are published.
Namespace Collisions
Vendor\ThemeName\).config/theme-manager-bridge.php to remap namespaces:
'theme_namespace_prefix' => 'App\\Themes\\',
Asset Pipeline Conflicts
mix-manifest.json is merged correctly. The bridge does not auto-discover Mix assets.resources/js/bootstrap.js:
window.themeAssets = {
'my-theme': require('../themes/my-theme/mix-manifest.json'),
};
Caching Issues
php contao:clear-cache
php artisan cache:clear
invalidateCache() method:
ThemeManagerBridge::invalidateCache('my-theme-package');
Symfony Dependency Conflicts
symfony/console), ensure versions align with Contao’s requirements (check contao/core-bundle).composer.json:
"require": {
"symfony/console": "5.4.*",
"contao/core-bundle": "^4.11"
}
Theme Updates
composer require oveleon/my-theme:^2.0 --update-with-dependencies
php artisan theme-manager-bridge:sync
Enable Debug Mode
Set debug: true in config/theme-manager-bridge.php to log theme operations:
'debug' => env('APP_DEBUG', false),
Check Theme Registration Verify themes are registered via:
dd(ThemeManagerBridge::getRegisteredThemes());
Symlink Issues
If assets fail to load, check symlinks in public/:
ls -la public/themes/
Rebuild symlinks with:
php artisan theme-manager-bridge:sync --force
Custom Theme Loaders
Extend the bridge’s theme loader by implementing Oveleon\ThemeManagerBridge\Contracts\ThemeLoaderInterface:
class CustomThemeLoader implements ThemeLoaderInterface {
public function load(string $themeName): array {
return ['path' => "/custom/path/to/{$themeName}"];
}
}
Bind it in a service provider:
$this->app->bind(ThemeLoaderInterface::class, CustomThemeLoader::class);
Theme Previews Integrate with Laravel’s view system to render theme previews:
// In a controller
return view('themes.preview', [
'theme' => ThemeManagerBridge::getThemePreview('my-theme-package'),
]);
API Integration Expose theme status via Laravel’s API:
Route::get('/api/themes', function () {
return ThemeManagerBridge::getActiveTheme();
});
Protect routes with middleware (e.g., auth:api).
Testing Mock the bridge in PHPUnit tests:
$this->app->instance(ThemeManagerBridge::class, Mockery::mock(ThemeManagerBridge::class));
Use ThemeManagerBridge::shouldReceive('activateTheme')->once() for assertions.
How can I help you explore Laravel packages today?