Applying a suggestion leaves the edit form's changed timestamp stale, so the next Save fails EntityChangedConstraint
### Problem/Motivation
Applying a suggestion from a review record's modal breaks the next save of the entity being edited.
`ReviewRunController::applySuggestion()` saves the reviewed entity directly, which advances its `changed` timestamp, and it does that outside the entity edit form's own submission. The module's intended flow puts that modal on top of the edit form: `FormHooks::formAlter()` adds an `.ai-review-sidebar` panel to every content entity form, whose record labels are `use-ajax` links with `data-dialog-type="modal"` opening `/ai-content-review/record/{id}/detail`, and that dialog carries the Apply buttons.
So after Apply the host form's hidden `changed` input is stale, and the next real Save trips core's `EntityChangedConstraint`: the error two colliding editors would get, hit by a single editor using the feature as designed.
Found on 1.0.0-alpha1.
#### Steps to reproduce
1. Configure a review rule for a content type and run a review on a node, so a completed record with at least one recommendation exists.
2. Edit that node (`/node/N/edit`).
3. Open the `Content Review` panel in the sidebar and click the record's label to open its modal.
4. Click **Apply** on a recommendation. It succeeds.
5. Close the modal and press **Save**.
Observed: the save is rejected by `EntityChangedConstraint`. With `autosave_form` installed it surfaces first as a dialog: "Autosave has been disabled. The content has been modified elsewhere. As a result, autosaving has been disabled and autosaved states for the current page have been deleted."
Measured on a Varbase 11 / Drupal 11.4 site: before Apply the node's `changed` was 1786954320 and the form's hidden input held the same; after Apply the database read 1790008468 while the hidden input still held 1786954320.
Expected: applying a suggestion from within the edit form leaves that form saveable.
Environment: Drupal 11.4, PHP 8.4, Varbase 11, with `autosave_form` and `content_lock` present. Neither is required to hit the bug; `autosave_form` only changes how it surfaces.
### Proposed resolution
Return the freshly saved `changed` timestamp from the apply endpoint and write it into the host form's hidden `changed` input client-side, so a save right after Apply no longer collides. It no-ops harmlessly on the standalone Review tab, where there is no such form.
1. `src/Controller/ReviewRunController.php` - `applySuggestion()` returns `new JsonResponse(['status' => 'applied'])`. Also return the subject's changed time when it implements `EntityChangedInterface`, read off the same object that was just saved (`$subject`) rather than a reloaded one, so it matches the value written.
2. `js/review_run.js` - in the Apply `$.ajax` success handler, when the response carries a `changed`, write it into the host form's hidden input.
The part that is easy to get wrong: the obvious `$btn.closest('form')` does not work. Drupal's dialog moves the record-detail markup into a `.ui-dialog` element appended to `<body>`, so by the time Apply is clicked the button is no longer a descendant of the entity edit form and `closest('form')` matches nothing. The hidden input is then silently never updated and the bug persists with no error anywhere. The host form has to be addressed directly, excluding any input inside the dialog itself:
```js
var $dialog = $btn.closest('.ui-dialog');
$('form input[name="changed"]')
.not($dialog.find('input[name="changed"]'))
.val(data.changed);
```
### Verified by the reporter
Checked against core's `EntityChangedConstraintValidator`, which compares `loadUnchanged()`'s changed time with the submitted entity's. Before the fix, Apply left the form's value stale and the following save failed. After the fix, in a real browser on 1.0.0-alpha1: the hidden value refreshed within a second of Apply, and the next Save completed and redirected to the node with no constraint error and no autosave dialog.
### Remaining tasks:
- [x] File an issue
- [ ] Addition/Change/Update/Fix
- [ ] Testing to ensure no regression
- [ ] Automated unit testing coverage
- [ ] Automated functional testing coverage
- [ ] UX/UI designer responsibilities
- [ ] Readability
- [ ] Accessibility
- [ ] Performance
- [ ] Security
- [ ] Developer Documentation
- [ ] User Guide Documentation
- [ ] Reviewed by human
- [ ] Code review by maintainers
- [ ] Full testing and approval
- [ ] Credit contributors
- [ ] Review with the product owner
- [ ] Release notes snippet
- [ ] Release
### API changes
* The apply endpoint's JSON response gains a `changed` key for subjects implementing `EntityChangedInterface`. Additive; existing consumers are unaffected.
### Data model changes
* N/A
### Release notes snippet
* Applying a suggestion from the node edit form no longer leaves the form unsaveable with a "content has been modified elsewhere" error on the next save.
AI-Generated: Yes
issue
GitLab AI Context
Project: project/ai_content_review
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/ai_content_review/-/raw/1.x/README.md — project overview and setup
- https://git.drupalcode.org/project/ai_content_review/-/raw/1.x/CLAUDE.md — Claude Code instructions
Repository: https://git.drupalcode.org/project/ai_content_review
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD