Skip to content

fix(legacy-edit-content): preserve relationship context across language switches#36001

Open
adrianjm-dotCMS wants to merge 2 commits into
mainfrom
35472-relationship-field-loses-context-on-language-switch
Open

fix(legacy-edit-content): preserve relationship context across language switches#36001
adrianjm-dotCMS wants to merge 2 commits into
mainfrom
35472-relationship-field-loses-context-on-language-switch

Conversation

@adrianjm-dotCMS
Copy link
Copy Markdown
Member

@adrianjm-dotCMS adrianjm-dotCMS commented Jun 5, 2026

Problem

Two related regressions in the legacy edit content screen when using relationship fields:

  1. "Return to [parent]" button disappears after switching language — the button was visible when first opening the child contentlet, but switching language reloaded the page and the button was gone.

  2. Relationship not created when switching language before saving — when creating a new child contentlet via "Relate New" and switching language before saving, the relationship with the parent was never established. The content was created but appeared unlinked.

Both issues only affected non-default languages. English (default) worked correctly.

Screen.Recording.2026-06-05.at.12.05.12.PM.mov

Root Cause

Both bugs share the same root: data stored for the language-switch navigation URL was incomplete.

Bug 1 — localStorage cleared too early:
showRelationshipReturn() called localStorage.removeItem() immediately after rendering the "Return to" button. On language switch the page reloaded, found localStorage empty, and skipped the button.

Bug 2 — Relationship params missing from editURL:
The language selector builds its URL from editURL, which was constructed without the relationship params (relwith, relisparent, reltype, relname, relname_inodes). Switching language navigated to a URL without those params, so on save EditContentletAction had no context to auto-link the new content to its parent.

Changes

edit_contentlet_basic_properties.jsp

  • Move localStorage.removeItem() into the button click handler so the "Return to" breadcrumb survives language-switch reloads; cleared only when the user actually navigates back to the parent.
  • When opening a form via "Relate New" (relwith != null), include all relationship params in editURL so they are preserved when changeLanguage() navigates to a different language version.

Test Plan

  • Open a contentlet with a relationship field
  • Click "Relate" → "Relate New Content", create and publish a child in English → relationship appears in parent ✓
  • Repeat but switch to Spanish before saving the child → relationship must appear in parent ✓
  • While on the child contentlet, switch language → "Return to [parent]" button must remain visible ✓
  • Click "Return to [parent]" → navigates back and button does not reappear ✓

Fixes #35472

…ge switches

When creating a child contentlet via "Relate New" from a relationship field,
switching language before saving caused the relationship params (relwith,
reltype, etc.) to be dropped from the URL, so the auto-link to the parent
was never created. Fix includes the localStorage cleanup for the "Return to"
breadcrumb button which had the same language-switch regression.

Fixes #35472

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jun 5, 2026

Claude finished @adrianjm-dotCMS's task in 51s —— View job


Rollback Safety Analysis

  • Read rollback-unsafe categories reference
  • Get full PR diff
  • Analyze diff against unsafe categories
  • Apply appropriate label

Result: ✅ Safe To Rollback

The changes in this PR are limited to a single JSP file (edit_contentlet_basic_properties.jsp) and touch no persistent storage or shared contracts.

Category-by-category check:

Category Assessment
C-1 Structural Data Model Change ✅ No — no DB schema or data storage changes
C-2 Elasticsearch Mapping Change ✅ No — no ES mapping or indexing changes
C-3 Content JSON Model Version Bump ✅ No — no contentlet_as_json model changes
C-4 DROP TABLE / DROP Column ✅ No — no DDL statements
H-1 One-Way Data Migration ✅ No — no data transformation tasks
H-2 RENAME TABLE / COLUMN ✅ No
H-3 PK Restructuring ✅ No
H-4 New Field Type ✅ No
H-5 Storage Provider Change ✅ No
H-6 DROP PROCEDURE / FUNCTION ✅ No
H-7 NOT NULL Column Without Default ✅ No
M-1 Non-Broadening Column Type Change ✅ No
M-2 Push Publishing Bundle Format Change ✅ No
M-3 REST / GraphQL API Contract Change ✅ No
M-4 OSGi Plugin API Breakage ✅ No

Summary of changes:

  1. Relationship params (relwith, relisparent, reltype, relname, relname_inodes) are now included in editURL when present — pure UI/navigation change, no persistent state altered.
  2. localStorage.removeItem() moved from page render time to button click handler — client-side browser storage only, no server-side state.

Rolling back to N-1 simply reverts these UI behaviors; no database state, ES index, or API contract is affected.

Label applied: AI: Safe To Rollback

Updated the logic in `edit_contentlet_basic_properties.jsp` to ensure that relationship parameters (`relisparent`, `reltype`, `relname`, `relname_inodes`) are only added to the URL if they are present in the request. This prevents potential issues with missing parameters when creating child contentlets, enhancing the reliability of the relationship linking process.
@adrianjm-dotCMS adrianjm-dotCMS marked this pull request as ready for review June 5, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Safe To Rollback Area : Backend PR changes Java/Maven backend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Relationship field loses parent breadcrumb when switching language in legacy edit content screen

1 participant