Skip to content

[Bug] Class editor: allowed-classes select shows duplicate options and drops classes (folder nodes leak into options) - #3930

Open
alexbaat wants to merge 1 commit into
pimcore:2026.2from
alexbaat:fix/class-definition-options-exclude-folder-nodes
Open

[Bug] Class editor: allowed-classes select shows duplicate options and drops classes (folder nodes leak into options)#3930
alexbaat wants to merge 1 commit into
pimcore:2026.2from
alexbaat:fix/class-definition-options-exclude-folder-nodes

Conversation

@alexbaat

@alexbaat alexbaat commented Jul 23, 2026

Copy link
Copy Markdown

Changes in this pull request

Resolves pimcore/platform-version#239

useClassDefinitionOptions builds the options for the allowed classes select shown in the class editor settings of all relation field types (manyToOneRelation, manyToManyRelation, manyToManyObjectRelation, both advanced* variants and reverseObjectRelation). It fetches the class definition tree with withGroup: true and flattens it — but flattenTreeNodes() emitted the folder (group) nodes themselves as selectable options in addition to their children.

Since ClassDefinitionTreeService (studio-backend-bundle) derives group names from class name prefixes for classes without an explicit group, a folder is frequently named exactly like a real class. Example: classes Material and MaterialGroup are grouped into a folder named Material, so the options contain Material twice (folder + class) plus phantom entries for groups that are not classes at all (Royalty, …).

Observed behaviour

  • The allowed-classes dropdown shows duplicate entries (e.g. Material twice, Product twice).
  • The duplicate option values / React keys break rendering of the virtualized dropdown list, so some perfectly valid classes (e.g. Series) no longer show up and cannot be selected.
  • Folder/group names can be picked and saved as an "allowed class" even though no such class exists.

Reproduction

  1. Create classes Material, MaterialGroup and Series (no explicit group set).
  2. Add a manyToOneRelation field to any class and open its settings in the class editor.
  3. Open the Allowed classes select: Material appears twice, Series is missing.

Fix

Skip folder nodes in flattenTreeNodes() and only recurse into their children — folders are grouping containers, not selectable class definitions. This mirrors what the neighbouring useClassRelationFieldsOptions hook already does. The special folder option added via the includeFolder parameter is unaffected.

Added a Jest spec covering: folder nodes excluded, no duplicate values when a folder shares its name with a class, includeFolder behaviour, and the not-yet-loaded state.

Additional info

The root cause has two halves: the prefix-based auto-grouping in ClassDefinitionTreeService::extractGroupNameFromClassName() (studio-backend-bundle) is what makes folder names collide with class names in the first place. This PR fixes the consumer side, which resolves the user-facing bug for all relation field types; rethinking the prefix grouping itself is left out of scope.

Reproduced on v2026.1.6 and the bug is still present on 2026.x/v2026.2.1.

The allowed-classes select in the class editor's relation field settings
built its options from the grouped class definition tree, including the
folder (group) nodes themselves. Group names derived from class name
prefixes often collide with real class names, producing duplicate option
values and phantom options, which breaks rendering of the dropdown so
that some classes become unselectable.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 23, 2026 10:03
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes invalid and duplicate class options in relation field settings by excluding grouping folders.

Changes:

  • Flattens only actual class-definition nodes.
  • Adds regression tests for duplicates, folder inclusion, and unloaded data.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
use-class-definition-options.ts Excludes folder nodes from selectable options.
use-class-definition-options.spec.ts Adds regression coverage for option generation.

@sonarqubecloud

Copy link
Copy Markdown

@alexbaat
alexbaat marked this pull request as ready for review July 23, 2026 10:06
@pimcore-deployments
pimcore-deployments marked this pull request as draft July 23, 2026 10:06
@alexbaat
alexbaat marked this pull request as ready for review July 23, 2026 10:20
@pimcore-deployments
pimcore-deployments marked this pull request as draft July 23, 2026 10:20
@alexbaat

Copy link
Copy Markdown
Author

recheck

@alexbaat

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@alexbaat
alexbaat marked this pull request as ready for review July 23, 2026 10:30
@ValeriaMaltseva
ValeriaMaltseva self-requested a review July 23, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants