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

API Channel: mapped numeric IDs get lost when using fieldsets #495

Closed
simon-matt-oetztal opened this issue Nov 26, 2024 · 3 comments · Fixed by #496
Closed

API Channel: mapped numeric IDs get lost when using fieldsets #495

simon-matt-oetztal opened this issue Nov 26, 2024 · 3 comments · Fixed by #496
Labels
Milestone

Comments

@simon-matt-oetztal
Copy link
Contributor

simon-matt-oetztal commented Nov 26, 2024

When the API Channel is using numeric IDs for the mapped fields, the IDs get lost when fieldsets are used.

In our case the mapped nodes array should look like this:
[ 46 => "1", 1 => "Simon", 2 => "Matt", 3 => "[email protected]", 14 => 10, 4548 => "2" ]

but looks like:
[ 0 => "1", 1 => "Simon", 2 => "Matt", 3 => "[email protected]", 4 => 10, 5 => "2" ]

This is caused by "array_merge":
https://github.com/dachcom-digital/pimcore-formbuilder/blob/master/src/OutputWorkflow/Channel/Api/ApiOutputChannelWorker.php#L131

solution: using "array_replace"

@solverat
Copy link
Member

solverat commented Jan 8, 2025

@simon-matt-oetztal: Hey Simon, thanks for the investigation. I'm not quite sure if this is the right way to do this. But I'm also not sure if I'm getting your issue in the first place! :)

I think there might be an issue regarding fieldsets with mapped/unmapped subfields, but I have to check it first. There is this notification at the bottom of the API mapping window:

"If an API field is assigned to the fieldset itself, the child elements will be created as an array branch. Otherwise, child elements will be assigned flat."

I've added it after the container field mapping feature came out, but I think there's something odd with it. I was not able to see subfields as an array branch, when I also set the mapping to the fieldset itself (so the statement is therefore not true).

Could you please provide me a screenshot of the API mapping window?

@simon-matt-oetztal
Copy link
Contributor Author

Hi @solverat,

sure, here's a screenshot:
image

The main issue is, that our field keys of the API are integers. So it's crucial to keep the correct integer as key in the array to be able to assign the values to the correct fields of the API.
As array_merge is used for joining the fields of the fieldset and the other fields. The integer keys get lost, or better said reordered.
Here's an example: https://onlinephp.io/array-merge?d=q1ZKLCpKrFSygtAaMRA6Pje1KD01RknB1k4hRsnQyDhGSQfIKC4pTUuDiBrrKBgaGIBYhppKOhBdRnBjDEESRjoKxiDaBKQVu7EmEHORhI1AppUBDbLQM9IzMlCqBQA%2C&v=8.2.20
image

Using array_replace would solve this:
https://onlinephp.io/array-replace?d=q1ZKLCpKrFSygtAaMRA6Pje1KD01RknB1k4hRsnQyDhGSQfIKC4pTUuDiBrrKBgaGIBYhppKOkpFqQU5icmpual5JcVwwwxB0kY6CsYg2gRkAHbDTSCmIwkbgcwsAxpkoWekZ2SgVAsA&v=8.2.20
image

I was not aware of the notification mentioned. But as you said the fields are returned flat.
It seems to be possible to assign the whole fieldset:
image
I would guess the fieldset is only returned as array if the whole fieldseet ist assigned? But this makes no sense in our case...

thx for your support!

@solverat
Copy link
Member

solverat commented Jan 9, 2025

@simon-matt-oetztal Thanks for the feedback. I'm able to reproduce it now.

array_replace overrides existing keys, that's why I went for array_merge. Since it is not allowed/possible to have duplicate keys but crucial to keep the mapping keys, this is perfectly fine.

Thank you!

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