Update AbstractMenuPackageInstallationPlugin with proper selection nesting
authorMatthias Schmidt <gravatronics@live.com>
Sat, 30 Jun 2018 08:59:44 +0000 (10:59 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 30 Jun 2018 08:59:44 +0000 (10:59 +0200)
See #2545

wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php

index 36740590146c5218a05741f9aad5b5a82b1a925b..27f30f783fac599a68b32950e435398451cb077f 100644 (file)
@@ -160,31 +160,39 @@ abstract class AbstractMenuPackageInstallationPlugin extends AbstractXMLPackageI
                                ->label('wcf.acp.pip.abstractMenu.parentMenuItem')
                                ->filterable()
                                ->options(function(): array {
-                                       $acpMenuStructureData = $this->getMenuStructureData();
-                                       $acpMenuStructure = $acpMenuStructureData['structure'];
-                                       $menuItemLevels = ['' => 0] + $acpMenuStructureData['levels'];
+                                       $menuStructure = $this->getMenuStructureData()['structure'];
                                        
-                                       // only consider menu items until the third level (thus only parent
-                                       // menu items until the second level) as potential parent menu items
-                                       $acpMenuStructure = array_filter($acpMenuStructure, function(string $parentMenuItem) use ($menuItemLevels): bool {
-                                               return $menuItemLevels[$parentMenuItem] <= 2;
-                                       }, ARRAY_FILTER_USE_KEY);
+                                       $options = [[
+                                               'depth' => 0,
+                                               'label' => 'wcf.global.noSelection',
+                                               'value' => ''
+                                       ]];
                                        
-                                       $buildOptions = function(string $parent = '', int $level = 0) use ($acpMenuStructure, &$buildOptions): array {
+                                       $buildOptions = function(string $parent = '', int $depth = 0) use ($menuStructure, &$buildOptions): array {
+                                               // only consider menu items until the third level (thus only parent
+                                               // menu items until the second level) as potential parent menu items
+                                               if ($depth > 2) {
+                                                       return [];
+                                               }
+                                               
                                                $options = [];
-                                               foreach ($acpMenuStructure[$parent] as $menuItem) {
-                                                       $options[$menuItem->menuItem] = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . WCF::getLanguage()->get($menuItem->menuItem);
+                                               foreach ($menuStructure[$parent] as $menuItem) {
+                                                       $options[] = [
+                                                               'depth' => $depth,
+                                                               'label' => $menuItem->menuItem,
+                                                               'value' => $menuItem->menuItem
+                                                       ];
                                                        
-                                                       if (isset($acpMenuStructure[$menuItem->menuItem])) {
-                                                               $options += $buildOptions($menuItem->menuItem, $level + 1);
+                                                       if (isset($menuStructure[$menuItem->menuItem])) {
+                                                               $options = array_merge($options, $buildOptions($menuItem->menuItem, $depth + 1));
                                                        }
                                                }
                                                
                                                return $options;
                                        };
                                        
-                                       return ['' => 'wcf.global.noSelection'] + $buildOptions();
-                               })
+                                       return array_merge($options, $buildOptions());
+                               }, true)
                                ->value(''),
                        
                        ClassNameFormField::create('menuItemController')