Skip to content

Commit 7a20074

Browse files
committed
Replace options_callback with event listener
1 parent 9947442 commit 7a20074

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

contao/dca/tl_metamodel.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,6 @@
565565
'label' => &$GLOBALS['TL_LANG']['tl_metamodel']['languages_langcode'],
566566
'exclude' => true,
567567
'inputType' => 'select',
568-
'options' => array_flip(array_filter(array_flip($this->getLanguages()), function ($langCode) {
569-
// Disable >2 char long language codes for the moment.
570-
return (strlen($langCode) == 2);
571-
})),
572568
'eval' => array
573569
(
574570
'style' => 'width:470px',

src/MetaModels/DcGeneral/Events/Table/MetaModels/Subscriber.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace MetaModels\DcGeneral\Events\Table\MetaModels;
2323

24+
use Contao\System;
2425
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\DecodePropertyValueForWidgetEvent;
2526
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\EncodePropertyValueFromWidgetEvent;
2627
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetBreadcrumbEvent;
@@ -31,6 +32,7 @@
3132
use ContaoCommunityAlliance\DcGeneral\Event\PostPersistModelEvent;
3233
use ContaoCommunityAlliance\DcGeneral\Event\PreDeleteModelEvent;
3334
use ContaoCommunityAlliance\UrlBuilder\UrlBuilder;
35+
use MenAtWork\MultiColumnWizard\Event\GetOptionsEvent;
3436
use MetaModels\DcGeneral\Events\BaseSubscriber;
3537
use MetaModels\DcGeneral\Events\BreadCrumb\BreadCrumbMetaModels;
3638
use MetaModels\Helper\TableManipulation;
@@ -79,6 +81,10 @@ function (GetBreadcrumbEvent $event) use ($serviceContainer) {
7981
PreDeleteModelEvent::NAME,
8082
array($this, 'handleDelete')
8183
)
84+
->addListener(
85+
GetOptionsEvent::NAME,
86+
array($this, 'loadLanguageOptions')
87+
)
8288
->addListener(
8389
DecodePropertyValueForWidgetEvent::NAME,
8490
array($this, 'fixLanguageLangArray')
@@ -240,6 +246,28 @@ public function unfixLangArray(EncodePropertyValueFromWidgetEvent $event)
240246
$event->setValue($output);
241247
}
242248

249+
/**
250+
* Prepare the language options.
251+
*
252+
* @param GetOptionsEvent $event The event.
253+
*
254+
* @return void
255+
*/
256+
public function loadLanguageOptions(GetOptionsEvent $event)
257+
{
258+
if (($event->getModel()->getProviderName() !== 'tl_metamodel')
259+
|| ($event->getPropertyName() !== 'languages')
260+
|| ($event->getSubPropertyName() !== 'langcode')
261+
|| $event->getOptions() !== []) {
262+
return;
263+
}
264+
265+
$event->setOptions(array_flip(array_filter(array_flip(System::getLanguages()), function ($langCode) {
266+
// Disable >2 char long language codes for the moment.
267+
return (strlen($langCode) == 2);
268+
})));
269+
}
270+
243271
/**
244272
* Decode a language array.
245273
*

0 commit comments

Comments
 (0)