spicywebau / craft-neo

A Matrix-like field type for Craft CMS that uses existing fields
Other
403 stars 63 forks source link

Problem with Neo draft behavior #925

Open stefangallas opened 1 month ago

stefangallas commented 1 month ago

Bug Description

Hello, I know that my request is somewhat vague. But unfortunately I have not yet been able to localise the error more precisely. There is a customised plugin that drafts a page including all content elements and then translates all the fields. An event is triggered for each field, via which the field receives its translation data if necessary. This used to work smoothly, but no longer does (without knowing me the time since it fails).

The point is, all standard craft fields on the page are still changed correctly and saved in the draft only. However, for all fields that are within a Neo structure, the translation is saved in both the draft and the regular entry. In this case, it seems as if no draft version of the Neo structure was created at all.

Is there a difference in what happens with a Neo field when a draft version is created in code with

Craft::$app->drafts->createDraft($entry, ...);

and then afterwards (after the translation) is saved via

Craft::$app->getElements()->saveElement($element, false, false);

Or perhaps you have another idea that could explain the different behaviour?

By the way, if I create a draft in the Craft BE everything works out as expected.

Steps to reproduce

Sorry, as that is a custom plugin there is no chance for you to reproduce it.

Expected behaviour

No response

Neo version

4.1.3

Craft CMS version

4.9.5

What is the affected Neo field's propagation method?

Only save blocks to the site they were created in

Does this issue involve templating, and if so, is eager-loading used?

This is not a templating issue

ttempleton commented 4 weeks ago

If you try this out with a Matrix field, does it work as expected?

stefangallas commented 3 weeks ago

Hey @ttempleton , thank you very much for your fast reply. I created a Matrix field and started the translation - and actually have the same behaviour as with the Neo field as described above. Apparently there really is a difference whether fields are built directly into the page or whether they are inside a Neo/Matrix field. So I will contact the Craft team directly - maybe they have an idea.