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

getSerializedFieldValues() on entry does not return deactivated blocks and breaks block structure #391

Open
christianruhstaller opened this issue Aug 12, 2020 · 3 comments

Comments

@christianruhstaller
Copy link

christianruhstaller commented Aug 12, 2020

Description

For the SiteCopy (https://github.com/Goldinteractive/craft3-sitecopy) to enable copying from one site to another we use the getSerializedFieldValues method on the entry to get the serialized form of the field layout to save it to another entry.

The problem is that the method does not return deactivated blocks (It just skips them).
For the copying this isn't nice but not a catastrophic error, except if you have a multi level structure and only the parent is deactivated but not the children then what happens is that the method getSerializedFieldValues returns the children but not the parent.

If we use the result of the method and save it to another entry we lose the parent block and the neo structure is broken/wrong.

Example with an accordion. We have a accordion wrapper which has the entries as its children:
Level 1: Accordion
Level 2 (Children): Accordion entry

Entry:
Neo field:

  • Accordion
    -- Accordion entry 1
    -- Accordion entry 2

After using the result from getSerializedFieldValues the structure will be:

  • Accordion entry 1
    -- Accordion entry 2

We lost the parent block "Accordion" and the funny thing is the child blocks are not on the same level anymore. If you open the entry it will take the first child and use it as a parent.

From the returned data from getSerializedFieldValues you would expect this:

  • Accordion entry 1
  • Accordion entry 2

But that does not happen.

getSerializedFieldValues should always return all the blocks no matter the status of the corresponding block and especially it should not create a bogus structure.

Any inputs/opinions on this? I hope my report is comprehensible. :D

Other information

  • Neo version: 2.7.24
  • Craft version: 3.4.29.1
@christianruhstaller christianruhstaller changed the title getSerializedFieldValues on entry does not return deactivated blocks and breaks block structure getSerializedFieldValues() on entry does not return deactivated blocks and breaks block structure Aug 12, 2020
@christianruhstaller
Copy link
Author

christianruhstaller commented Aug 12, 2020

Addendum: It seems that the matrix has the same behavior. It seems that this is a bigger issue and maybe even the wrong method to handle copying.

I think it would be okay if deactivated blocks do not returned at all but at least the integrity of the structure should be maintained.

@ttempleton
Copy link
Contributor

I explained in a bit more detail in #372 how the behaviour of a Neo field's serializeValue() method is consistent with Matrix and structure section entry queries, and why serializeValue()'s return value should therefore not be considered reliable structure data if only enabled blocks are included. That said, I did also discuss whether enabled blocks should be excluded when querying for enabled blocks if they have a disabled ancestor; at this point (for consistency with structure section entry queries) I'm inclined to leave it as it is, but it's worth considering.

I think disabled blocks should be returned by getSerializedFieldValues() -- or at least have the option to set that -- and that the ideal solution to this would be if we could set anyStatus() on the block query if getSerializedFieldValues() is involved, but that doesn't seem possible at the moment as far as I can tell.

@lukasNo1
Copy link

As a workaround, in the SiteCopy plugin we override the getSerializedFieldValues() function to return both enabled and disabled elements for now. Goldinteractive/craft3-sitecopy@91334a1#diff-85a66352a4b6e09286584934d796f53eR284

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

No branches or pull requests

3 participants