contao/manager-plugin
Provides Contao Manager integration hooks for Composer packages. Lets extensions register with the Contao Manager, add configuration and plugin logic for installs/updates, and streamline compatibility with the Contao CMS Manager workflow.
Installation Add the package via Composer in your Laravel project (if applicable—note: this is a Contao Manager plugin, not a Laravel-specific package, but can be adapted for Laravel-based Contao integrations):
composer require contao/manager-plugin
Note: This package is primarily for Contao CMS, but if you're using Laravel with Contao via a bridge (e.g., laravel-contao), ensure compatibility.
Register the Plugin
In your Contao installation, add the plugin to config/config.php under managerPlugins:
$GLOBALS['TL_MANAGER_PLUGINS'][] = 'vendor\\manager\\plugin\\ClassName';
First Use Case
Create a basic plugin class extending Contao\ManagerPlugin\AbstractPlugin:
namespace Vendor\ManagerPlugin;
use Contao\ManagerPlugin\AbstractPlugin;
use Contao\ManagerPlugin\Configuration\Version;
class MyPlugin extends AbstractPlugin
{
public function getConfiguration()
{
return new Version('1.0.0', '1.0.0', '1.0.0', '2023-01-01', 'Contao 4.9+');
}
}
getConfiguration() to define metadata (version, compatibility).onLoad, onInstall) for lifecycle events.Plugin Lifecycle Hooks Leverage hooks to integrate with Contao Manager’s workflow:
public function onInstall()
{
// Run migrations, setup tasks, or post-install logic.
}
public function onUninstall()
{
// Cleanup logic (e.g., delete database entries).
}
Dependency Management
Declare dependencies in getConfiguration():
public function getConfiguration()
{
return new Version(
'1.0.0',
'1.0.0',
'1.0.0',
'2023-01-01',
'Contao 4.9+',
['contao/core-bundle' => '4.9.*'] // Example dependency
);
}
UI Integration (Optional)
Extend the Manager UI by implementing getMenuItems() or getSubscribedServices() for custom admin panels or services.
Laravel Adaptation (If Applicable) If using Laravel with Contao, wrap the plugin in a Laravel service provider to bridge events:
// app/Providers/ContaoManagerPluginServiceProvider.php
public function boot()
{
if (class_exists('Contao\ManagerPlugin\Manager')) {
$manager = new \Contao\ManagerPlugin\Manager();
$manager->registerPlugin(new \Vendor\ManagerPlugin\MyPlugin());
}
}
Namespace Conflicts
Ensure plugin classes use unique namespaces (e.g., Vendor\ManagerPlugin\*) to avoid collisions with Contao core or other plugins.
Version Mismatches
TL_Exception during installation.composer.json constraints to align with Contao’s semver (e.g., ^4.9).Hook Timing
onLoad runs during plugin initialization but before dependencies are resolved. Use onInstall for dependency-heavy logic.getConfiguration() (e.g., file I/O).Laravel-Specific Quirks
Schema::table() carefully.Enable Debug Mode
Set TL_DEBUG to true in config/localconfig.php to log Manager plugin errors:
define('TL_DEBUG', true);
Check Manager Logs
Errors appear in /system/logs/contao_manager.log (if logging is configured).
Validate Configuration
Use php bin/contao-manager.php list to verify plugin registration:
./contao-manager.php list
Custom Commands
Extend Contao Manager’s CLI with getCommands():
public function getCommands()
{
return [
new \Vendor\ManagerPlugin\CustomCommand(),
];
}
Dynamic Plugin Loading Load plugins conditionally based on environment variables or Contao features:
public function onLoad()
{
if (TL_MODE === 'BE' && \Input::get('key') === 'my_plugin') {
// Enable plugin only in backend.
}
}
Asset Bundling
For frontend assets, use Contao’s asset pipeline or Laravel Mix, then reference them in getConfiguration():
public function getAssets()
{
return [
'css' => 'bundles/myplugin/style.css',
'js' => 'bundles/myplugin/script.js',
];
}
How can I help you explore Laravel packages today?