Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: With autosaveDrafts disabled, saving entry with validation errors causes issues with Matrix/Neo blocks #15418

Closed
ttempleton opened this issue Jul 26, 2024 · 1 comment
Labels

Comments

@ttempleton
Copy link

What happened?

Description

When the autosaveDrafts setting is disabled, when saving an entry that had previously failed to save due to validation errors, some of the non-field data for Matrix/Neo blocks is omitted from the POST data. This causes things like disabled state to be lost, and Neo block levels being lost leading to loss of Neo block structure (related issue: spicywebau/craft-neo#907).

Steps to reproduce

  1. Set autosaveDrafts to false in CMS config
  2. Create a new entry with a Matrix field set to display as blocks
  3. Add a Matrix entry and set it as disabled
  4. Don't put in a required field
  5. Save the owner entry. Craft will give a validation error
  6. Fix that validation error and save it again
  7. After saving the owner entry, the Matrix entry is enabled

Expected behavior

Matrix entry stays disabled after saving owner entry

Actual behavior

Matrix entry is enabled after saving owner entry

Craft CMS version

5.2.8

PHP version

8.2.20

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

  • Neo 5.1.0
@brandonkelly
Copy link
Member

Thanks for reporting that!

Culprit was that this code no longer really applies to newly-added nested Matrix entries, since we now create actual new entries immediately when you press “New [entry type]” over Ajax:

{% if entry.id %}
{% do view.registerDeltaName(baseInputName) %}
{% endif %}

So delta names were getting registered for every nested entry’s input namespace (which covers …[enabled]), even for entries that had just been created.

Fixed by having newly-created nested entries start life as unpublished drafts, so we can check for in that condition:

{% if entry.id and not entry.getIsUnpublishedDraft() %}
{% do view.registerDeltaName(baseInputName) %}
{% endif %}

Since the fix was a bit involved, I decided to do it on the 5.3 branch, which will be going out in a couple weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants