Problem
When multiple profiles per user are allowed, and the profile form is displayed on the user account form, the first profile is displayed multiple times and any changes made overwrite the data from the first profile, causing a loss of stored data.
Steps to reproduce
- Define a Profile Type (let's call it "Pet") with text field "Name"
- Select the option to "Allow multiple profiles per user"
- Under Configuration / People / Account Settings / Manage form display, enable the display of "Pet Profiles" and set the widget to "Profile Form".
- Add two Pet profiles to a particular user, say "Rover" and "Killer".
- Edit that user. Notice that 3 profile forms are displayed, all with "Rover". Change the third one to "Frank".
- Observe that Rover is now Frank and Killer is unchanged.
Proposed resolution
I believe the root of this problem is that the form state contains an array of profiles, indexed by profile type. Thus only the data from one profile of a given type is stored.
Remaining tasks
Fix the bug.
User interface changes
None
API changes
Unknown. The internal structure of the profiles in the form state may need to change.
Data model changes
None.
I reluctantly assigned the Priority of Critical because this bug causes a loss of stored data when the form is submitted. It can be reasonably argued that the circumstances that are needed to exhibit the bug are sufficiently uncommon that a lower priority such as major is appropriate.
Comment | File | Size | Author |
---|---|---|---|
#6 | profile-edit_multiple-3315270-6.patch | 3.48 KB | DanChadwick |
#3 | 3315270-profile-edit-multiple-3.patch | 4.25 KB | tBKoT |
#2 | profile-edit_multiple-3315270-2.patch | 3.46 KB | DanChadwick |
Issue fork profile-3315270
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
DanChadwick CreditAttribution: DanChadwick commentedThis patch changes the storage of the profiles in the form state from an array of profiles indexed by profile type to an associative array (indexed by profile type) of arrays (indexed by delta) of profiles. This would be a backward-breaking change if any custom module relies on the storage of the profiles in the form state.
Comment #3
tBKoT CreditAttribution: tBKoT at Lemberg Solutions commentedThe patch from #2 is almost working for me. The issue I'm facing after applying it is that whenever we edit user info and save changes a new empty profile is created. So I added a condition to remove empty profiles from the form state, it works only for new items.
Comment #4
DanChadwick CreditAttribution: DanChadwick as a volunteer commentedNeither #2 nor #3 apply to 1.8. In reviewing #3, I feel this is a distinct issue -- should new empty profiles be saved? This applies both to single and multiple profile entity references. I suggest @tBKoT create a new issue. First question is do you simply not save new empty profiles, or do you delete existing profiles which became empty. I would advocate the latter, but this is a change in behavior. This could be accomplished with something like:
, but might be better in
saveProfiles
.Since patch-based testing is being discontinued, I will open an issue fork for a re-roll of #2.
Comment #5
DanChadwick CreditAttribution: DanChadwick as a volunteer commentedComment #6
DanChadwick CreditAttribution: DanChadwick as a volunteer commentedReroll of #2, leaving the empty profile changes of #3 to a to-be-created separate issue. Patch for convenience of composer workflow.
Comment #8
DanChadwick CreditAttribution: DanChadwick as a volunteer commentedCatch 22. Drupal 9 support ended November 1st. The latest version of Drupal 9 required PHP 7.4, which includes support for arrow functions, which I used in this patch. But I cannot start a test with PHP 7.4 without using Drupal 10, which requires a composer.json file. So either I need to remove the arrow function just to make the linting pass, or we need to make profile be Drupal 10 testing compatible.
Comment #10
jsacksick CreditAttribution: jsacksick at Centarro commentedI committed your patch. If you're in the mood for writing a change record, that'd be great... Added the following note to the release notes for now:
Comment #11
DanChadwick CreditAttribution: DanChadwick as a volunteer commentedDraft change record created.
Comment #12
drupalfan2 CreditAttribution: drupalfan2 as a volunteer commentedAfter upgrading from profile 1.8 to 1.9 I get this error message:
Same problem with profile 1.10.
I do not allow multiple profiles per user, "Allow multiple profiles per user" is off.
And patch #16 of https://www.drupal.org/project/profile/issues/2599014 does not apply anymore.
I need a solution to get profile 1.9 and 1.10 running.
Comment #13
drupalfan2 CreditAttribution: drupalfan2 as a volunteer commented#12 is solved here: https://www.drupal.org/project/profile/issues/3437825
Comment #14
jsacksick CreditAttribution: jsacksick at Centarro commented@DanChadwick: Where is the change record?
Comment #15
DanChadwick CreditAttribution: DanChadwick as a volunteer commented@jsacksick: Scroll up. It should be in the right sidebar at the bottom. Unless only I see it? I think a maintainer has to publish it, maybe?
https://www.drupal.org/node/3432547