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

Allow multiple values with same location without swapping primary keys #148

Open
wants to merge 4 commits into
base: 7.x-4.x
Choose a base branch
from
Open

Allow multiple values with same location without swapping primary keys #148

wants to merge 4 commits into from

Conversation

beto-aveiga
Copy link
Contributor

@beto-aveiga beto-aveiga commented Jul 13, 2018

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.

peek 2018-07-16 16-34

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.

peek 2018-07-16 16-37

@mattwire
Copy link
Collaborator

@powdevel #147 has now been merged.

To reproduce the error saving updates:

  1. Enable phone type custom fields (via api explorer or other).
$result = civicrm_api3('OptionValue', 'create', [
  'option_group_id' => "cg_extend_objects",
  'name' => "Phone",
  'label' => "Phone",
  'value' => "civicrm_phone",
]);
  1. Add a custom field of type phone.
  2. Add that custom field to a webform.
  3. On first submit of webform (ie. phone is created, all values are saved).
  4. On second submit of webform (with same phone), only the "phone" parameter is updated.

With the patch in #147 all submitted values are updated.

@beto-aveiga
Copy link
Contributor Author

@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 :)

@beto-aveiga
Copy link
Contributor Author

@mattwire I already documented the PR, sorry for the late. Hope it is clear now.

@colemanw
Copy link
Owner

@mattwire it would be great if you could test this out.

@beto-aveiga
Copy link
Contributor Author

@colemanw I will, once I finish a few tasks I will test this PR. Thanks.

@beto-aveiga
Copy link
Contributor Author

@KarinG @colemanw I merged locally #146 and #148 into the master of this repo. I made several tests and everything worked just fine.
I tested with multiple emails, multiple addresses, and multiple phones. Also tested with multiple fields with location types selectable by the user, and the results were the the expected results.
If there is something else to do please tell me, I need the both mentioned branches get merged as soon as possible to incorporate those changes in a patched version of webform_civicrm, for CiviHR and probably CiviCRM.
Thanks!

@beto-aveiga
Copy link
Contributor Author

@KarinG @colemanw is there anything else from my side so this PR could be merge? I'm just trying to be sure if you are waiting something from me. Thanks.

@colemanw colemanw added the 7.x label Aug 2, 2019
@jamienovick
Copy link

@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;
Copy link
Owner

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

Suggested change
$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;

Copy link
Contributor

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.

@colemanw
Copy link
Owner

@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.

@jamienovick
Copy link

jamienovick commented Sep 13, 2019

@colemanw will do!

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

Successfully merging this pull request may close these issues.

5 participants