heimrichhannot / contao-dc-multilingual-utils-bundle
This bundle offers functionality concerning terminal42/contao-DC_Multilingual for the Contao CMS.
Installs: 352
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Type:contao-bundle
Requires
- php: ^7.4 || ^8.0
- contao/core-bundle: ^4.13
- heimrichhannot/contao-utils-bundle: ^2.216
- terminal42/dc_multilingual: ^4.0
README
This bundle offers functionality concerning terminal42/contao-DC_Multilingual for the Contao CMS.
Features
- adds multilanguage support for tl_content
- adds shortcut functions for rapidly activating DC_Multilingual support for a given DCA
- adds multilanguage support for madeyourday/contao-rocksolid-custom-elements
- adds insert tags for generating multilingual event, news or faq urls
- caution: overrides the id handling of DC_Multilingual v4+ to the v3 behavior (the record with the joined translation has its id set to the id of the translation record)
Installation
- Install via composer:
composer require heimrichhannot/contao-dc-multilingual-utils-bundle
. - Activate
DC_Multilingual
support fortl_content
(not optional):
/** * @Hook("loadDataContainer") */ class LoadDataContainerListener { private DcMultilingualUtil $multilingualUtil; public function __invoke(string $table): void { if ('tl_content' === $table) { $this->multilingualUtil->addDcMultilingualSupport( $table, ['de', 'en', 'pl'], 'de', [ 'text', 'rsce_data' ] ); } } }
Technical details
Insert tags
The following new tags are available:
Activate DC_Multilingual rapidly using the shortcut functions
Simply call the following code:
/** * @Hook("loadDataContainer") */ class LoadDataContainerListener { private DcMultilingualUtil $multilingualUtil; public function __invoke(string $table): void { if ('tl_content' === $table) { $this->multilingualUtil->addDcMultilingualSupport( $table, // Table name ['de', 'en', 'pl'], // Supported languages 'de', // Fallback language [ // the translatable fields 'text', // add fields here... 'rsce_data' // add this if you have rocksolid custom elements (tl_content only) ], [ // options 'langColumnName', // the language field in the dca's records (you have a record for every language and this column holds which one it is) 'langPid', // this field holds the parent record of every translated record ] ); break; } } }
Notes on overridden classes
For generating content elements which respect the multilanguage records created using DC_Multilingual in the backend,
it's necessary to override the ContentModel
, because Contao calls the core's ContentModel directly in Controller
:
$objRow = ContentModel::findByPk($intId);
But for getting Contao to output the translated Elements, we need to use our own ContentModel
inheriting from the class
Terminal42\DcMultilingualBundle\Model\Multilingual/Multilingual
.