Skip to content

Conversation

@saifsultanc
Copy link
Contributor

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

…ach Child Entries to Parent when Editing via Gravity Flow.
@saifsultanc saifsultanc requested review from veryspry and removed request for claygriffiths March 8, 2025 10:24
Copy link
Contributor

@veryspry veryspry left a 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' );
Copy link
Contributor

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

Copy link
Contributor Author

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.
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2025

Walkthrough

A 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 (gpnf_set_parent_entry_id) that checks if the parent entry ID is unset and if the current page is a workflow detail page. In such a case, it retrieves the parent entry ID from the request using rgget('lid') and assigns that value, ensuring that the child entry is correctly attached to its parent entry.

Changes

File Path Change Summary
gp-nested-forms/gpnf-gflow-auto-attach-child-entries.php Introduces automatic parent-child entry attachment by adding a filter (gpnf_set_parent_entry_id). The filter checks the current workflow detail page and assigns a parent ID from the request if not set.

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
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against 0c7a96f

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8a2d9f9 and 0c7a96f.

📒 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_id if rgget('lid') returns a falsy value.

@saifsultanc saifsultanc merged commit c575683 into master Mar 12, 2025
3 of 4 checks passed
@saifsultanc saifsultanc deleted the saif/add/77386-add-gpnf-flow-child-entry branch March 12, 2025 06:19
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.

3 participants