Skip to content

Show content validation errors when Saving Ajaxy - #3793

Merged
bobvandevijver merged 4 commits into
6.1from
mindaugasjackunaspc-fix/validation-errors-on-ajaxy-save
Aug 13, 2026
Merged

Show content validation errors when Saving Ajaxy#3793
bobvandevijver merged 4 commits into
6.1from
mindaugasjackunaspc-fix/validation-errors-on-ajaxy-save

Conversation

@bobvandevijver

Copy link
Copy Markdown
Member

Resubmit of #3769.

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

This PR fixes the “ajaxy save” path so that content-validation failures are returned as JSON (rather than HTML) and can be displayed in the editor UI without a full page reload, matching the classic (non-ajax) UX for validation feedback.

Changes:

  • Add a dedicated JSON (HTTP 422) response for content-validation violations on XHR saves.
  • Update the ajaxy-save JS handler to safely render validator messages (text-only) and show inline alert blocks above the edit form.
  • Add a PHPUnit test covering the controller’s ajaxy validation-error JSON contract.

Reviewed changes

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

File Description
tests/php/Controller/Backend/ContentEditControllerSaveTest.php Adds a controller unit test for ajaxy validation-error JSON responses.
src/Controller/Backend/ContentEditController.php Returns validator violations as JSON (422) for XHR saves via a new helper.
assets/js/app/ajax-save.js Displays validation errors inline and sanitizes toast body by using .text().
Suppressed comments (2)

tests/php/Controller/Backend/ContentEditControllerSaveTest.php:100

  • Setting the protected $config property via ReflectionProperty::setValue() requires setAccessible(true) (as done in other tests like tests/php/Twig/TokenParserTestCase.php). Without it, this assignment can fail and leave $this->config uninitialized, breaking the test.
        (new ReflectionProperty(TwigAwareController::class, 'config'))->setValue($controller, $this->configWithValidatorEnabled());

assets/js/app/ajax-save.js:139

  • Code style in this file consistently uses a space between function and the parameter list (e.g. function (toastEl) above). The new callback uses function(error), which is inconsistent and may trip linting.
                    let messages = response.errors.map(function (error) {

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/php/Controller/Backend/ContentEditControllerSaveTest.php
Comment thread src/Controller/Backend/ContentEditController.php
Comment thread assets/js/app/ajax-save.js Outdated
@bobvandevijver
bobvandevijver merged commit 07ba5e6 into 6.1 Aug 13, 2026
35 checks passed
@bobvandevijver
bobvandevijver deleted the mindaugasjackunaspc-fix/validation-errors-on-ajaxy-save branch August 13, 2026 19:41
@bobvandevijver bobvandevijver changed the title Mindaugasjackunaspc fix/validation errors on ajaxy save Show content validation errors when Saving Ajaxy Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants