Make `categoryMultiSelectOptionType.tpl` behave like `categoryOptionList.tpl`
authorMaximilian Mader <max@bastelstu.be>
Tue, 14 Sep 2021 16:19:15 +0000 (18:19 +0200)
committerMaximilian Mader <max@bastelstu.be>
Tue, 14 Sep 2021 16:19:15 +0000 (18:19 +0200)
Currently the `categoryMultiSelectOptionType.tpl` outputs nodes of depth 0 and depth 1,
but article categories for example can be nested deeper than that.
The `categoryOptionList.tpl` as used by the category add forms handles arbitrary nesting levels already,
so I’ve ported the template logic over to the multi select option template.

The maximum nesting depth in the `AbstractCategoryMultiSelectOptionType.class.php` has been changed
to the default value (-1) to allow for infinite nesting depths.

wcfsetup/install/files/acp/templates/categoryMultiSelectOptionType.tpl
wcfsetup/install/files/lib/system/option/AbstractCategoryMultiSelectOptionType.class.php

index cc7cd54ab8a11e059826f09364e24c562280e719..1a36d16537494ada0a861ca184e3df873446c5a2 100644 (file)
@@ -1,11 +1,7 @@
 <select id="{$option->optionName}" name="values[{$option->optionName}][]" multiple size="10">
-       {foreach from=$categoryList item=categoryItem}
-               <option value="{@$categoryItem->categoryID}"{if $categoryItem->categoryID|in_array:$value} selected{/if}>{$categoryItem->getTitle()}</option>
-               
-               {if $categoryItem->hasChildren()}
-                       {foreach from=$categoryItem item=subCategoryItem}
-                               <option value="{@$subCategoryItem->categoryID}"{if $subCategoryItem->categoryID|in_array:$value} selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;{$subCategoryItem->getTitle()}</option>
-                       {/foreach}
+       {foreach from=$categoryList item='category'}
+               {if !$maximumNestingLevel|isset || $maximumNestingLevel == -1 || $categoryNodeList->getDepth() < $maximumNestingLevel}
+                       <option value="{$category->categoryID}"{if $category->categoryID|in_array:$value} selected{/if}>{section name=i loop=$categoryList->getDepth()}&nbsp;&nbsp;&nbsp;&nbsp;{/section}{$category->getTitle()}</option>
                {/if}
        {/foreach}
 </select>
\ No newline at end of file
index 90f91a75660169a36ccdf61a4c857012b3beb605..75e913345608c3a579de134c8ee9f20f7aedcc3e 100644 (file)
@@ -35,7 +35,6 @@ abstract class AbstractCategoryMultiSelectOptionType extends AbstractOptionType
                /** @var CategoryNodeTree $categoryTree */
                $categoryTree = new $this->nodeTreeClassname($this->objectType);
                $categoryList = $categoryTree->getIterator();
-               $categoryList->setMaxDepth(0);
                
                WCF::getTPL()->assign([
                        'categoryList' => $categoryList,