|
21 | 21 |
|
22 | 22 | namespace MetaModels\DcGeneral\Events\Table\MetaModels; |
23 | 23 |
|
| 24 | +use Contao\System; |
24 | 25 | use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\DecodePropertyValueForWidgetEvent; |
25 | 26 | use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\EncodePropertyValueFromWidgetEvent; |
26 | 27 | use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetBreadcrumbEvent; |
|
31 | 32 | use ContaoCommunityAlliance\DcGeneral\Event\PostPersistModelEvent; |
32 | 33 | use ContaoCommunityAlliance\DcGeneral\Event\PreDeleteModelEvent; |
33 | 34 | use ContaoCommunityAlliance\UrlBuilder\UrlBuilder; |
| 35 | +use MenAtWork\MultiColumnWizard\Event\GetOptionsEvent; |
34 | 36 | use MetaModels\DcGeneral\Events\BaseSubscriber; |
35 | 37 | use MetaModels\DcGeneral\Events\BreadCrumb\BreadCrumbMetaModels; |
36 | 38 | use MetaModels\Helper\TableManipulation; |
@@ -79,6 +81,10 @@ function (GetBreadcrumbEvent $event) use ($serviceContainer) { |
79 | 81 | PreDeleteModelEvent::NAME, |
80 | 82 | array($this, 'handleDelete') |
81 | 83 | ) |
| 84 | + ->addListener( |
| 85 | + GetOptionsEvent::NAME, |
| 86 | + array($this, 'loadLanguageOptions') |
| 87 | + ) |
82 | 88 | ->addListener( |
83 | 89 | DecodePropertyValueForWidgetEvent::NAME, |
84 | 90 | array($this, 'fixLanguageLangArray') |
@@ -240,6 +246,28 @@ public function unfixLangArray(EncodePropertyValueFromWidgetEvent $event) |
240 | 246 | $event->setValue($output); |
241 | 247 | } |
242 | 248 |
|
| 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 | + |
243 | 271 | /** |
244 | 272 | * Decode a language array. |
245 | 273 | * |
|
0 commit comments