oneup/contao-language-dependent-modules-bundle

Configure your Contao modules language dependent and have less page layouts!

1.2.0 2022-09-12 14:32 UTC

This package is auto-updated.

Last update: 2024-12-12 19:45:24 UTC


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.

CI Total Downloads

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: Bildschirmfoto 2020-05-13 um 10 25 13

and include this module in your layout: Bildschirmfoto 2020-05-13 um 10 44 04

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.