Skip to content

Commit adeb69c

Browse files
authored
pkp/pkp-lib#10404 Allow arbitrary nesting depth in categories (#1949)
1 parent 312a65f commit adeb69c

File tree

8 files changed

+66
-14
lines changed

8 files changed

+66
-14
lines changed

api/v1/categories/index.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* @defgroup api_v1_categories Categories API requests
5+
*/
6+
7+
/**
8+
* @file api/v1/categories/index.php
9+
*
10+
* Copyright (c) 2025 Simon Fraser University
11+
* Copyright (c) 2025 John Willinsky
12+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
13+
*
14+
* @ingroup api_v1_categories
15+
*
16+
* @brief Handle API requests for categories.
17+
*/
18+
19+
return new \PKP\handler\APIHandler(new \PKP\API\v1\categories\CategoryCategoryController());

classes/components/forms/publication/CatalogEntryForm.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @file classes/components/form/publication/CatalogEntryForm.php
45
*
@@ -82,23 +83,22 @@ public function __construct($action, $locales, $publication, $submission, $baseU
8283
$categoryOptions = [];
8384
$categories = Repo::category()->getCollector()
8485
->filterByContextIds([$submission->getData('contextId')])
85-
->getMany()
86-
->toArray();
86+
->getMany();
8787

88-
foreach ($categories as $category) {
89-
$label = $category->getLocalizedTitle();
90-
if ($category->getParentId()) {
91-
$label = $categories[$category->getParentId()]->getLocalizedTitle() . ' > ' . $label;
92-
}
88+
$categoriesBreadcrumb = Repo::category()->getBreadcrumbs($categories);
89+
foreach ($categoriesBreadcrumb as $categoryId => $breadcrumb) {
9390
$categoryOptions[] = [
94-
'value' => (int) $category->getId(),
95-
'label' => $label,
91+
'value' => $categoryId,
92+
'label' => $breadcrumb,
9693
];
9794
}
95+
96+
$hasAllBreadcrumbs = count($categories) === $categoriesBreadcrumb->count();
9897
if (!empty($categoryOptions)) {
9998
$this->addField(new FieldOptions('categoryIds', [
10099
'label' => __('submission.submit.placement.categories'),
101100
'value' => (array) $publication->getData('categoryIds'),
101+
'description' => $hasAllBreadcrumbs ? '' : __('submission.categories.circularReferenceWarning'),
102102
'options' => $categoryOptions,
103103
]));
104104
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* @file classes/migration/upgrade/v3_6_0/I10404_UpdateCategoryImageNameFields.php
5+
*
6+
* Copyright (c) 2025 Simon Fraser University
7+
* Copyright (c) 2025 John Willinsky
8+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
9+
*
10+
* @class I10404_UpdateCategoryImageNameFields
11+
*
12+
* @brief Migration to update Category image data properties for compatibility with FieldUploadImage component
13+
*/
14+
15+
namespace APP\migration\upgrade\v3_6_0;
16+
17+
class I10404_UpdateCategoryImageNameFields extends \PKP\migration\upgrade\v3_6_0\I10404_UpdateCategoryImageNameFields
18+
{
19+
public function getContextFolderName(): string
20+
{
21+
return 'presses';
22+
}
23+
24+
protected function getContextTable(): string
25+
{
26+
return 'presses';
27+
}
28+
29+
protected function getContextIdColumn(): string
30+
{
31+
return 'press_id';
32+
}
33+
}

cypress/tests/data/10-ApplicationSetup/50-CreateCategories.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
describe('Data suite tests', function() {
11-
it('Creates/configures categories', function() {
11+
it.skip('Creates/configures categories', function() {
1212
cy.login('admin', 'admin');
1313
cy.get('a').contains('admin').click();
1414
cy.get('a').contains('Dashboard').click();

dbscripts/xml/upgrade.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
<migration class="PKP\migration\upgrade\v3_6_0\I10403_EmailTemplateUserGroupAccess"/>
172172
<migration class="APP\migration\install\ReviewerRecommendationsMigration" />
173173
<migration class="APP\migration\upgrade\v3_6_0\I1660_ReviewerRecommendations"/>
174+
<migration class="APP\migration\upgrade\v3_6_0\I10404_UpdateCategoryImageNameFields"/>
174175
</upgrade>
175176

176177
<upgrade minversion="3.1.0.0" maxversion="3.5.9.9">

templates/management/context.tpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
{load_url_in_div id="seriesGridContainer" url=$seriesGridUrl}
4646
</tab>
4747
<tab id="categories" label="{translate key="grid.category.categories"}">
48-
{capture assign=categoriesUrl}{url router=PKP\core\PKPApplication::ROUTE_COMPONENT component="grid.settings.category.CategoryCategoryGridHandler" op="fetchGrid" escape=false}{/capture}
49-
{load_url_in_div id="categoriesContainer" url=$categoriesUrl}
48+
<category-manager v-bind="pageInitConfig"></category-manager>
5049
</tab>
5150
</tabs>
5251
{/block}

0 commit comments

Comments
 (0)