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

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

Merged
merged 9 commits into from
Nov 15, 2024

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
Memoize custom fields by their handle within FieldLayout so we don't need to memoize them within the element in the first place
[ci skip]
@brandonkelly brandonkelly merged commit feed27e into 5.x Nov 15, 2024
@brandonkelly brandonkelly deleted the bugfix/16056-entry-type-change-and-field-content branch November 15, 2024 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants