Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When displaying a list of entities, using views, which are rendered using a the field render entity with a selected view mode and all the rendered entities include a state transition form. Then all the form on the pages will only update the first rendered entity.
Proposed Resolution
Allow each form instance to have its own form ID.
Example
Here is an example of how this issue might occur, the screenshot below shows a transition form for each order item:
Comments
Comment #2
nikathoneAnd here is the patch. Took the same approach as in https://github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/cart/src... but this will need anybody implementing a
hook_form_FORM_ID_alter()
to update their code if accepted.Comment #3
smazI had this issue on a view, and the patch provided fixes the issue - many thanks.
I've marked needs work, for the following (a nitpick really):
Can we not shorten that to just:
If not for whatever reason, then feel free to mark this as RTBC!
Comment #4
josephdpurcell CreditAttribution: josephdpurcell at Digital Bridge Solutions commentedI ran into this issue as well. The patch from #2 works.
Putting the increment in the constructor should be avoided, but I am not aware of a better pattern for addressing this type of issue.
I'm uploading a patch that implements the suggestion in #3, and setting to RTBC.
Comment #5
josephdpurcell CreditAttribution: josephdpurcell at Digital Bridge Solutions commentedUpdated description with an example of how this problem might arise.
Comment #6
jcandan CreditAttribution: jcandan as a volunteer commented#4 is working great!
Comment #7
uniquename CreditAttribution: uniquename commentedworks fine for me!
Comment #8
bojanz CreditAttribution: bojanz at Centarro commentedWe did the static counter approach in Commerce, and ended up with a bunch of bugs, where the static wasn't updated properly on #ajax.
We had to replace it with a more stable solution. So, let's use the entity type and ID here instead of the static counter.
Comment #10
bojanz CreditAttribution: bojanz at Centarro commentedRewrote the patch and committed. Thanks, everyone!
Comment #11
sittard CreditAttribution: sittard commentedWe are currently using State Machine 8.x-1.0-beta3 and we need this patch. Are we OK to migrate to the dev branch or should we wait for a beta 4 release? Thanks.
Comment #12
bojanz CreditAttribution: bojanz at Centarro commentedReleased RC1, you can update to that.
Comment #13
sittard CreditAttribution: sittard commentedSuper - Thanks ;)