-
Notifications
You must be signed in to change notification settings - Fork 109
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
Allow multiple values with same location without swapping primary keys #148
base: 7.x-4.x
Are you sure you want to change the base?
Allow multiple values with same location without swapping primary keys #148
Conversation
@powdevel #147 has now been merged. To reproduce the error saving updates:
With the patch in #147 all submitted values are updated. |
@mattwire thanks for your explanation. I'm going to test that outside of my work schedule. Right now I have to document the PRs I did and create patches for 7.x-4.20 because that is for today soon :) |
@mattwire I already documented the PR, sorry for the late. Hope it is clear now. |
@mattwire it would be great if you could test this out. |
@colemanw I will, once I finish a few tasks I will test this PR. Thanks. |
@KarinG @colemanw I merged locally #146 and #148 into the master of this repo. I made several tests and everything worked just fine. |
@colemanw - whilst we are fixing things could we try and close this one off? If it need modificaiton let me know and I'll ask @vinuvarshith to look at it. |
@@ -764,6 +760,9 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base { | |||
// start array index at 1 | |||
$existing = array_merge(array(array()), $result['values']); | |||
} | |||
// Check which location_type_id is to be set as is_primary=1; | |||
$is_primary_location_type = isset($contact[$location][1]['location_type_id']) ? $contact[$location][1]['location_type_id'] : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be written more concisely as
$is_primary_location_type = isset($contact[$location][1]['location_type_id']) ? $contact[$location][1]['location_type_id'] : null; | |
$is_primary_location_type = $contact[$location][1]['location_type_id'] ?? NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colemanw I made this change and it works fine.
But just to note, the is only available on PHP 7.x and I guess its ok for 7.x-5.x branch.
@jamienovick if you could ask @vinuvarshith to grab this patch and make a new PR against the 7.x-5.x branch & then test it out that would be great. I've made 1 code-level suggestion but haven't tested it myself. |
@colemanw will do! |
Overview
Webform CiviCRM does not support multiple fields with same location type, for example: 3 emails of location type personal.
This lack of support for multiple fields also creates related issues as the swapping of primary keys on save, and even data corruption (only if webform is configured with multiple fields with same location)
The objective of this task is to enhance webform_civicrm capabilities to allow multiple fields with any location types (repeated or not) work as expected in the same webform, without swapping primary keys unexpectedly between the configured fields and saving all values in a predictable way.
Before
When saving multiple fields with the same location type the last value that changes will be saved as the primary field.
All fields are same location type. Notice the order of values before and after submit.
After
When saving multiple fields with the same location type the first value will remain as the primary field, no matter if it changes or not.
All fields are same location type. Notice the order of values before and after submit.