-
Notifications
You must be signed in to change notification settings - Fork 92
gpnf-gflow-auto-attach-child-entries.php: Added snippet to Auto-attach Child Entries to Parent when Editing via Gravity Flow.
#1017
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
Conversation
…ach Child Entries to Parent when Editing via Gravity Flow.
veryspry
left a comment
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.
I added one question / potential improvement, but it's totally up to your discretion @saifsultanc since this is out of my normal territory.
The code looks totally solid to me and I'm okay merging if it works for the customer 🤝
| */ | ||
| add_filter( 'gpnf_set_parent_entry_id', function( $parent_entry_id ) { | ||
| if ( ! $parent_entry_id && is_callable( 'gravity_flow' ) && gravity_flow()->is_workflow_detail_page() ) { | ||
| $parent_entry_id = rgget( 'lid' ); |
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.
Any chance rget( 'lid' ) could be empty in this context?
(This is truly a naive question since I don't really know how any of this works.)
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.
@veryspry Point taken. Just default back to whatever was if 'lid' fetches an empty value! :)
…ach Child Entries to Parent when Editing via Gravity Flow.
WalkthroughA new PHP file is introduced to enable the automatic association of child entries with their respective parent entries during form submissions in Gravity Flow within the Gravity Forms Nested Forms plugin. The file defines a filter hook ( Changes
Sequence Diagram(s)sequenceDiagram
participant User as End User
participant GF as Gravity Flow Handler
participant Filter as gpnf_set_parent_entry_id Filter
participant Request as Request Variable (rgget('lid'))
User->>GF: Submit child entry form
GF->>Filter: Trigger filter to set parent entry ID
Filter->>Filter: Check if parent entry ID is unset
Filter->>GF: Verify current page is a workflow detail page
Filter->>Request: Retrieve 'lid' parameter
Request-->>Filter: Return parent entry ID (if available)
Filter-->>GF: Return modified parent entry ID
GF->>GF: Attach child entry to the identified parent entry
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
gp-nested-forms/gpnf-gflow-auto-attach-child-entries.php (2)
14-14: Consider adding validation for the entry ID.While the code does check if
rgget('lid')returns a value, it doesn't validate that the value is a valid entry ID. Consider adding type checking or ensuring it's a positive integer.- $parent_entry_id = rgget( 'lid' ) ? rgget( 'lid' ) : $parent_entry_id; + $lid = rgget( 'lid' ); + $parent_entry_id = ($lid && is_numeric($lid) && $lid > 0) ? $lid : $parent_entry_id;
13-15: Consider adding error logging.In case something unexpected happens when retrieving the parent entry ID, it might be helpful to add error logging. This would make troubleshooting easier if the auto-attachment doesn't work as expected in certain scenarios.
if ( ! $parent_entry_id && is_callable( 'gravity_flow' ) && gravity_flow()->is_workflow_detail_page() ) { $lid = rgget( 'lid' ); + if ( !$lid && defined('WP_DEBUG') && WP_DEBUG ) { + error_log('GPNF: Unable to auto-attach child entry - parent entry ID not found in request.'); + } $parent_entry_id = rgget( 'lid' ) ? rgget( 'lid' ) : $parent_entry_id; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gp-nested-forms/gpnf-gflow-auto-attach-child-entries.php(1 hunks)
🔇 Additional comments (1)
gp-nested-forms/gpnf-gflow-auto-attach-child-entries.php (1)
1-17: Implementation looks solid for the described use case.The code provides a clean solution to the problem of child entries not automatically attaching to parent entries when editing via Gravity Flow. The implementation is concise and follows WordPress coding standards.
Regarding the previous question about
rgget('lid')potentially being empty - the code does handle this case in line 14 with the ternary operator, which falls back to the original$parent_entry_idifrgget('lid')returns a falsy value.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/2834613157/77386
Summary
A new child form entry that is added within a GravityFlow update input workflow is not auto-attached to the parent form until the parent form is submitted.
Similar to GravityView: https://gravitywiz.com/snippet-library/gpnf-gv-auto-attach-child-entries/
Loom: https://www.loom.com/share/44434c1fc8b346e1bcbcac3240e629cd