Entity form: build entity - can get only the first value of a multi-field value on node add

Created on 18 September 2024, 2 months ago

Hello,

Not sure if it's a bug, but when trying to display all the values of a multi-value field using ECA 2.0.5 and Drupal 11.0.4., only the first value is shown when adding the node, and on edit all values are displayed.

I need all the values of that field during validation and Entity form: build entity seems to be the solution only when editing the node, not when adding it.

Am I doing something wrong there?

Attached is a 1min video demonstrating the problem on simplytest.me, and the exported model.

Thank you!

💬 Support request
Status

Active

Version

2.0

Component

Documentation

Created by

🇷🇴Romania gge

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @gge
  • 🇷🇴Romania gge

    Back with additional information:

    All the values are correctly displayed when the node is created if the field is not unlimited.

    Now the question is how can we get all the values if the field is unlimited?

    Thank you!

  • 🇩🇪Germany jurgenhaas Gottmadingen

    I haven't tested it yet, but looking at the code in \Drupal\eca_form\Plugin\Action\FormBuildEntity::execute, ECA just calls $form_object->buildEntity($form, $form_state) at the very end. That's all from Drupal core, and if anything went wrong, that would indicate a core issue.

    There is one line that may indicate another source of the issue: on line 136 the form object gets cloned with $form_object = clone $form_object;. I've seen core issues when cloning an entity before.

    You could try 2 things: either test the whole thing with that cloning removed? This wouldn't be for your production site, just to test if that makes any difference. If it doesn't, then you may want to use xdebug and go through that $form_object->buildEntity to see where it goes wrong.

  • 🇷🇴Romania gge

    When commenting out $form_object = clone $form_object; all the values are displayed on node add, the issue seems to be solved, but are there any side effects if that line is removed?

    Thanks!

  • 🇩🇪Germany jurgenhaas Gottmadingen

    When commenting out $form_object = clone $form_object; all the values are displayed on node add

    This is great news.

    are there any side effects if that line is removed?

    Probably yes. It's in there so that we can be certain not to create any unintended changes to the form object.

    With your test results it sound pretty certain that there is a core issue with cloning the entity. In order to report this as a bug in the drupal issue queue, you would require more details so that one would know what's wrong. As a starting point, I'd do a comparison of the form object in the cloned and non-cloned version. Maybe that provides some indication.

    Unfortunately, I currently can't offer more time for this as DrupalCon and a few other commitments are very demanding.

  • 🇷🇴Romania gge

    Understood, thank you very much!

Production build 0.71.5 2024