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

gpnf-override-parent-merge-tag-on-submission.php: Fixed an issue with parent merge tags not updating Time value on entry edit. #905

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

saifsultanc
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/2725972610/72284

Summary

The snippet gpnf-override-parent-merge-tag-on-submission works for all default values besides the "Hour", "Minute" and "AM/PM" default values from the Time field.

Steps to Reproduce the issue:

  1. Create a parent and child form
  2. add a Time field to both forms. On the child form, set the "Hour", "Minute" and "AM/PM" default values to the {Parent:X} merge tag.
  3. install and configure snippet gpnf-override-parent-merge-tag-on-submission
  4. Go to parent form, enter a random time, add a new child entry, and then submit the parent form.
  5. Go to edit parent entry and change the values of the time field, then update.
  6. Now go to child entry and notice that time has not been overwritten by the new time.

The issue was because the time field stores the value as a string on entry, so "11:12 PM". So if the time field has its field ID 7, we will have $entry[7] containing that time string "11:12 PM". So we must fetch the string part via 7 and not 7.1, 7.2 etc. This is what this proposed update focuses on.

After Update:
https://www.loom.com/share/be2f4d27721c4af691f0776bf57baa60

…th parent merge tags not updating Time value on entry edit.
…th parent merge tags not updating Time value on entry edit.
…th parent merge tags not updating Time value on entry edit.
…th parent merge tags not updating Time value on entry edit.
@saifsultanc
Copy link
Contributor Author

@claygriffiths The "calculations" update on the snippet is done.

Here is a quick loom demo: https://www.loom.com/share/2cecdbeb81534f53b38d51c14e765bd1

// Process/Calculate the formula
$parsed_formula = GFCommon::replace_variables( $formula, $form, $entry, false, false, false, 'text' );
// phpcs:ignore Squiz.PHP.Eval.Discouraged
$calculated_value = eval( 'return ' . $parsed_formula . ';' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Directly callign the eval seems suspicious. We should run that through existing logic.

Here's how we recalc with another snippet: https://github.com/gravitywiz/snippet-library/blob/master/experimental/gpdtc-recalc.php

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

Successfully merging this pull request may close these issues.

2 participants