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

Fix state display on preview #941

Merged
merged 4 commits into from
May 4, 2024
Merged

Conversation

jitendrapurohit
Copy link
Collaborator

Overview

Fix state display on preview

Before

Existing Contact

After

Contact 1

Technical Details

The state has numerous options that we do not define as #options in the YAML configuration due to its daisy-chaining load based on country selection.

This PR adds a format function for label displays. I believe it should also fix the tokens @MegaphoneJon.

Comments

Drupal Ticket: https://www.drupal.org/project/webform_civicrm/issues/3410313

@avallllovera
Copy link

Tested. It worked.

@KarinG
Copy link
Collaborator

KarinG commented Jan 30, 2024

I kicked off the tests by making an edit to the main.yml file that I needed to make any way! :-)

@MegaphoneJon
Copy link
Contributor

My client is reporting that this doesn't fix the [webform_submission::values] token in emails. I'll try to look into this myself first though, since I think this PR is most of the fix. I think we may just need to check if the value is numeric rather than whether the type is "Text".

$state_id = $value;
}
else {
$state_id = $value['#plain_text'] ?? NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're sending an email with state_province_id fields, and the email is in HTML format, $value['#plain_text'] doesn't exist. I this we want $state_id = $value['#plain_text'] ?? $value['#markup'] ?? NULL;.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MegaphoneJon If i use the default body having[webform_submission:values] token to render all submission, it does work for me after the current PR. (Screenshot from email)

image

If i use a custom body with field tokens [webform_submission:values: civicrm_1_contact_1_address_state_province_id], it still works and renders the state correctly in email

image

The debug value of $text is Html & $value does have #plain_text in this function -

image

I'm fine to include your change if $value['#markup'] works for you. But curious to know your usecase since we have a similar implementation for Existing Contact, so i think [webform_submission:values:civicrm_1_contact_1_contact_existing] token might break for you too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jitendra,

That's not what I'm seeing. Attached is a webform export that displays the state/province as an ID.

Selection_2143

state id issue.yml.txt

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the attached webform still works fine on my end. Both Preview and email has state label instead of an id. Also, the debug values are same.

image

I believe I'll proceed with your suggestion since it appears to be a safe addition and works on your end :)

@jitendrapurohit jitendrapurohit force-pushed the stateoptions branch 3 times, most recently from 92152b1 to 4b57ac4 Compare February 11, 2024 05:31
@MegaphoneJon
Copy link
Contributor

I've been running the current version of this patch in production for a few months now with no issues, it looks good. I recommend removing the commented-out line in WebformCivicrmPostProcess.php but otherwise this LGTM.

@jitendrapurohit
Copy link
Collaborator Author

ah thanks for pointing that out. Have removed the line.

@KarinG
Copy link
Collaborator

KarinG commented May 4, 2024

Thank you all!

@KarinG KarinG merged commit 1051b35 into colemanw:6.x May 4, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants