Skip to content
New issue

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

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

Already on GitHub? # to your account

when entry type changes, reset element container fields & content #16076

Open
wants to merge 5 commits into
base: 5.x
Choose a base branch
from

Conversation

i-just
Copy link
Contributor

@i-just i-just commented Nov 11, 2024

Description

When switching an entry type for an Entry, ensure that if the old and new fields have the same handle, they also have compatible field types. If not, remove that handle from the memoized _fieldsByHandle array and un-normalize that field’s value. The same should happen if both the old and new fields implement ElementContainerFieldInterface and the two fields are not the exact same field.

Test case 1:

  • entryType1 has a matrix field with a handle of pageContent;
  • entryType2 has a different matrix field with an overwritten field handle set to pageContent;
  • In this case, the content was falsely showing on the screen after changing to entryType2, leading you to believe that it would be saved when you save your changes. If you reloaded the page or saved the entry, the content was gone.

Test case 2:

  • entryType1 has a matrix field with a handle pageContent;
  • entryType2 has a plain text field with a handle pageContent;
  • In this case, the entryType2 was getting a value of craft\elements\db\ElementQuery.

Test case 3:

  • entryType1 has a plain text field with a handle pageContent;
  • entryType2 has a matrix field with a handle pageContent;
  • In this case, after switching to entryType2 an error was thrown Call to a member function all() on string.

Related issues

#16056

@i-just i-just marked this pull request as ready for review November 11, 2024 18:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant