contao-components/installer
Custom Composer installer for Contao components. Installs packages of type "contao-component" into a dedicated directory (e.g., assets) configured via composer.json extra "contao-component-dir".
Install the Package:
composer require contao-components/installer
Add to your project’s composer.json:
"extra": {
"contao-component-dir": "plugins" // Custom directory for Contao components
}
Create a Contao Component:
"type": "contao-component" in its composer.json:
{
"name": "vendor/contao-widget",
"type": "contao-component",
"require": {
"contao-components/installer": "^1.0"
}
}
Require the Component in Laravel:
composer require vendor/contao-widget
Verify installation in plugins/vendor/.
Configure Autoloading:
Update composer.json to include Contao namespaces:
"autoload": {
"psr-4": {
"App\\": "app/",
"Vendor\\Contao\\": "plugins/vendor/" // Map Contao component namespace
}
}
Run:
composer dump-autoload
Test Basic Functionality:
use Vendor\Contao\Widget\ExampleClass;
$instance = new ExampleClass(); // Verify no autoload errors
"type": "contao-component".composer install in the component repo to test locally.composer.json and run composer update.monolog/monolog), ensure Laravel’s composer.json includes it to avoid conflicts.
"require": {
"monolog/monolog": "^3.0",
"vendor/contao-widget": "^1.0"
}
"require": {
"vendor/contao-widget": "1.0.0"
}
composer.json:
"autoload": {
"psr-4": {
"Vendor\\Contao\\": "plugins/vendor/src/"
}
}
config/autoload.php), add:
"autoload": {
"files": ["plugins/vendor/config/autoload.php"]
}
AppServiceProvider:
public function register()
{
$this->app->bind(
\Vendor\Contao\Widget\ExampleClass::class,
\Vendor\Contao\Widget\ExampleClass::class
);
}
// ContaoWidgetFacade.php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class ContaoWidgetFacade extends Facade
{
protected static function getFacadeAccessor()
{
return 'contao.widget';
}
}
Register in config/app.php:
'aliases' => [
'ContaoWidget' => App\Facades\ContaoWidgetFacade::class,
],
DCA structure:
Schema::create('tl_contao_widgets', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->timestamps();
});
config.php or system.php in Laravel’s bootstrap:
// In AppServiceProvider's boot()
$this->loadContaoConfig();
private function loadContaoConfig()
{
if (file_exists($path = base_path('plugins/vendor/config/config.php'))) {
require $path;
}
}
Route::prefix('contao')->group(function () {
Route::get('/widget/{id}', function ($id) {
// Load Contao component and render
return view('contao.widget', ['id' => $id]);
});
});
Route::middleware(['web', 'auth'])->prefix('contao')->group(function () {
Route::get('/backend', [ContaoBackendController::class, 'index']);
});
Class not found errors for Contao components.composer.json.composer dump-autoload --optimize and verify the namespace path in vendor/composer/autoload_psr4.php.
Ensure the contao-component-dir in composer.json matches the actual directory.phpunit/phpunit).composer why-not vendor/package to diagnose conflicts.
Override dependencies in composer.json:
"conflict-resolution": {
"prefer-lowest": true,
"owned": {
"monolog/monolog": "3.0.0"
}
}
Class 'Vendor\Contao\ClassName' not found despite correct autoloading.config/app.php:
'aliases' => [
'ContaoWidget' => Vendor\RenamedContaoNamespace\Widget::class,
],
TL_ROOT, $GLOBALS['TL_CONFIG']) that Laravel overrides.public function boot()
{
if (!defined('TL_ROOT')) {
define('TL_ROOT', base_path('plugins/vendor'));
}
if (!isset($GLOBALS['TL_CONFIG'])) {
$GLOBALS['TL_CONFIG'] = [];
}
}
DCA structure. Example for a tl_contao_widgets table:
Schema::create('tl_contao_widgets', function (Blueprint $table) {
$table->id();
$table->string('title')->nullable();
$table->text('content')->nullable();
$table->integer('pid')->unsigned()->nullable();
$table->integer('sorting')->unsigned()->default(0);
$table->timestamps();
});
composer update.php artisan cache:clear
php artisan view:clear
php artisan config:clear
Rebuild Composer autoloader:
composer dump-autoload
contao-component-dir in composer.json must be an absolute path relative to the project root. Example:
"extra": {
"contao-component-dir": "plugins/vendor"
}
How can I help you explore Laravel packages today?