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]: Matrix field containing an Entries field with the same handle as the matrix, always returns an empty array #16153

Open
vsylvestre opened this issue Nov 19, 2024 · 2 comments
Labels

Comments

@vsylvestre
Copy link

vsylvestre commented Nov 19, 2024

What happened?

Description

With Craft 5 we now have the possibility to change the handle of a field, which means that the handle of a Matrix field might be the same as one of the fields of the entries it contains. When doing so with an Entries field within a Matrix, the Matrix always returns an empty array.

Note that there are also issues when the field inside the Matrix is not an Entries type. If I try with a Plain Text field for instance, Craft will return an internal error. However, Entries seems like the weirdest case, since I'm getting no errors, only an empty array.

Steps to reproduce

I'll focus on the case with the Entries type.

  1. Create a "sectionEntries" field with type set to "Entries".
  2. Create a "section" entry type which contains the "sectionEntries" field.
  3. Create a "section" Matrix field which maps to the "section" entry type.
  4. Add the field to a page/entry, and rename the handle to "sectionEntries".
  5. The top-level "sectionEntries" Matrix field always returns an empty array.

Expected behavior

I would expect either to have an error indicating that we shouldn't nest fields with the same handles, or for nested handles to be supported.

In the case of a Plain Text field (instead of an Entries field): Craft does return an error, but I believe the message could be clearer. Here's what Craft returns:

"debugMessage": "craft\\helpers\\StringHelper::shortcodesToEmoji(): Argument #1 ($str) must be of type string, array given, called in *** on line 168",
"message": "Internal server error",
"extensions": {
    "category": "internal"
},

Actual behavior

In the case of an Entries field within a Matrix field, the Matrix field always returns an empty array.

In the case of a Plain Text field within a Matrix field, Craft returns a bit of a cryptic error.

Thank you!

Craft CMS version

5.5.2

PHP version

8.3.13

Operating system and version

Linux 4.18.0-553.16.1.el8_10.x86_64

Database type and version

MySQL 8.0.40

Image driver and version

GD 8.3.13

Installed plugins and versions

Image

@vsylvestre vsylvestre added the bug label Nov 19, 2024
@i-just
Copy link
Contributor

i-just commented Nov 20, 2024

Hi, thanks for getting in touch! I’m not able to replicate this. Can you share your code that results in an empty array being returned for the sectionEntries Matrix field?

@vsylvestre
Copy link
Author

Hi! Sorry for the delayed response.

I really should have specified in my original post: I get this issue when using the GraphQL API.

In the example I gave, the request would look something like this:

query GetEntry {
	page: entry {
		... on page_Entry {
			sectionEntries {
				... on section_Entry {
					sectionEntries {
						id
					}
				}
			}
		}
	}
}

... with the first sectionEntries being the Matrix field, and the second being the Entry field.

Could this be a limitation of the GraphQL API?

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