diff --git a/CHANGELOG-1.5.md b/CHANGELOG-1.5.md index bdb0e46c6c..127d957100 100644 --- a/CHANGELOG-1.5.md +++ b/CHANGELOG-1.5.md @@ -11,6 +11,7 @@ CHANGELOG - ZIKULA 1.5.x - Fixed broken search result url handling for new-style modules. - Improved detection and naming of available PDO drivers (#3785). - Use uncached JS routes (#3807). + - Fixed issue with category retrieval by path (#3815). - Vendor updates: - ? diff --git a/src/system/CategoriesModule/Api/CategoryApi.php b/src/system/CategoriesModule/Api/CategoryApi.php index a76d4e8aa9..4c20fd2253 100644 --- a/src/system/CategoriesModule/Api/CategoryApi.php +++ b/src/system/CategoriesModule/Api/CategoryApi.php @@ -229,6 +229,25 @@ public function getCategoryByPath($apath, $pathField = 'path', $sort = '', $incl $values = []; foreach ($apath as $path) { $parts = explode('/', $path); + + if ($pathField == 'path') { + $parts = array_values(array_filter($parts)); + + if (!empty($parts)) { + $last = count($parts) - 1; + + foreach ($parts as $part_key => $part_value) { + $criteria = []; + if ($part_key == 0) { + $criteria = ['name' => $parts[$part_key]]; + } elseif ($part_key != $last) { + $criteria = ['name' => $parts[$part_key], 'parent' => $parent]; + } + $parent = $repo->findOneBy($criteria)->getId(); + } + } + } + $values[] = array_pop($parts); } if (count($values) > 1) {