oneup / contao-language-dependent-modules-bundle
Configure your Contao modules language dependent and have less page layouts!
Installs: 3 205
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 6
Forks: 0
Open Issues: 0
Type:contao-bundle
Requires
- php: ^7.4 | ^8.0
- contao/core-bundle: ^4.9
- doctrine/dbal: ^2.13 || ^3.0
Requires (Dev)
- contao/manager-plugin: ^2.0
- contao/news-bundle: ^4.9
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.0
- phpstan/phpstan-doctrine: ^1.0
- phpstan/phpstan-symfony: ^1.0
- phpunit/phpunit: ^9.5
README
This Contao bundle provides a special module where you can configure your modules based on available languages.
This bundle is made for Contao 4.9 and newer.
Why this bundle?
The idea is to get rid of multiple page layouts (or inserttags with module IDs in combination with {{iflng::*}}
tags) for multiple languages.
Usage
You can now easy configure you modules for every language available:
and include this module in your layout:
This module will then render the configured module for each configured language.
Developers
The bundle provides an additional input type to use in your own code:
Use the default configuration (loads all available modules):
<?php // config/dca/tl_modules.php $GLOBALS['TL_DCA']['tl_module']['fields'] += [ 'myLanguageDependentModules' => [ 'inputType' => 'languageDependentModulesSurrogate', 'eval' => [ 'tl_class' => 'w50', ], 'sql' => 'blob NULL', ], ];
There is even more and you can customize this widget to your needs:
use options
(for custom list of modules):
<?php // config/dca/tl_modules.php $GLOBALS['TL_DCA']['tl_module']['fields'] += [ 'myLanguageDependentModules' => [ 'inputType' => 'languageDependentModulesSurrogate', 'options' => [ 0 => 'My module 0', 1 => 'My module 1', ], 'eval' => [ 'tl_class' => 'w50', ], 'sql' => 'blob NULL', ], ];
use options_callback
(for custom list of modules):
<?php // config/dca/tl_modules.php $GLOBALS['TL_DCA']['tl_module']['fields'] += [ 'myLanguageDependentModules' => [ 'inputType' => 'languageDependentModulesSurrogate', 'options_callback' => ['my.service_id', 'methodName'], 'eval' => [ 'tl_class' => 'w50', ], 'sql' => 'blob NULL', ], ]; // you can also use this with service tagging, see https://docs.contao.org/dev/framework/dca/#registering-callbacks
use eval['modules']
(to filter for custom types):
<?php // config/dca/tl_modules.php $GLOBALS['TL_DCA']['tl_module']['fields'] += [ 'myLanguageDependentModules' => [ 'inputType' => 'languageDependentModulesSurrogate', 'eval' => [ 'tl_class' => 'w50', 'modules' => [ 'navigation', 'customnav', 'search', 'html', 'myCustomModule', ], ], 'sql' => 'blob NULL', ], ];
Change the label for the blank option:
<?php // config/dca/tl_modules.php $GLOBALS['TL_DCA']['tl_module']['fields'] += [ 'myLanguageDependentModules' => [ 'inputType' => 'languageDependentModulesSurrogate', 'eval' => [ 'tl_class' => 'w50', 'blankOptionLabel' => 'My Label' ], 'sql' => 'blob NULL', ], ];
Note: If you just want to change the label for the blank option of the default field, the key is: tl_module.languageDependentModulesBlankOptionLabel
.