Skip to content

gppa-colorpicker-choice-template.php: Added Color Picker choice template for GPPA to work with Jet Sloth Color Picker plugin. #1081

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

Merged
merged 2 commits into from
May 1, 2025

Conversation

saifsultanc
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/2908760149/82217

Summary

Jetsloth Gravity Forms Color Picker doesn't work on a dynamically populated field. Add support for using Jetsloth Gravity Forms Color Picker on a GPPA populated field

Loom (Samuel):
https://www.loom.com/share/072f38457d3347bbac3c4771bb3b883e

We have added support it. How it looks after snippet added:
https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c

…plate for GPPA to work with Jet Sloth Color Picker plugin.
Copy link

coderabbitai bot commented Apr 21, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

A new PHP file has been added that defines the GPPA_Compatibility_JetSloth_Color_Picker_Template class. This class integrates a "Color Picker" template row into the Gravity Forms Populate Anything plugin interface. It hooks into the plugin's filtering and action mechanisms to support processing and displaying a custom color picker choice template, specifically for use with Jet Sloth's Color Picker plugin. The class modifies both backend template processing and the form editor's JavaScript to recognize and handle the new color picker template. Instantiation of the class at the end of the file activates these integrations.

Changes

File(s) Change Summary
gp-populate-anything/gppa-colorpicker-choice-template.php Added new file defining GPPA_Compatibility_JetSloth_Color_Picker_Template class; hooks into choice template processing and editor JS to support a custom "Color Picker" template for Populate Anything plugin.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Form Editor (Admin)
    participant JS as Editor JavaScript
    participant PHP as GPPA_Compatibility_JetSloth_Color_Picker_Template (PHP)
    participant PA as Populate Anything Plugin

    Admin->>JS: Open Populate Anything field editor
    JS->>JS: Apply filter to template rows
    JS->>JS: Add "Color Picker" template row if context is 'choices'

    PA->>PHP: Filter gppa_input_choice (process template)
    PHP->>PA: Add 'colorPicker_color' to choice if template present
    PA->>PA: Process template value for color picker
Loading

Possibly related PRs

Suggested reviewers

  • veryspry

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed284af and 025dfcb.

📒 Files selected for processing (1)
  • gp-populate-anything/gppa-colorpicker-choice-template.php (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

Copy link

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

Generated by 🚫 dangerJS against ed284af

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: 1

🧹 Nitpick comments (2)
gp-populate-anything/gppa-colorpicker-choice-template.php (2)

16-21: Prevent class re-declaration & add PHPDoc
To avoid fatal errors if this file is loaded more than once, wrap the class definition in a class_exists guard. Also, adding a PHPDoc block for the class improves maintainability.

- class GPPA_Color_Picker_Template {
+ if ( ! class_exists( 'GPPA_Color_Picker_Template' ) ) {
+     /**
+      * Adds a custom "Color Picker" choice template for GPPA.
+      */
+     class GPPA_Color_Picker_Template {

…and close the guard after instantiation:

- new GPPA_Color_Picker_Template();
+     new GPPA_Color_Picker_Template();
+ }

23-31: Improve template existence check
Currently you rely on rgar() truthiness which skips empty templates. For consistency, use isset() to detect the presence of the key, even if set to an empty string.

-    if ( rgar( $templates, 'colorPicker_color' ) ) {
+    if ( isset( $templates['colorPicker_color'] ) ) {
         $choice['colorPicker_color'] = gp_populate_anything()->process_template(
             $field,
             'colorPicker_color',
             $object,
             'choices',
             $objects
         );
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c8de01 and ed284af.

📒 Files selected for processing (1)
  • gp-populate-anything/gppa-colorpicker-choice-template.php (1 hunks)
🔇 Additional comments (2)
gp-populate-anything/gppa-colorpicker-choice-template.php (2)

33-51: JS registration of template row is correctly implemented
Using the gform_editor_js action to inject a gppa_template_rows filter and escaping the label with esc_js() is spot-on. No changes needed here.


54-55: Instantiate the class to activate hooks
Instantiating the class at the end ensures your filters and actions are registered. This is correct.

Comment on lines +1 to +15
<?php
/**
* Gravity Perks // Populate Anything // Add Custom Template Row for Color Picker
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*
* Instructions Video: https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c
*
* Adds "Color Picker" template row to the Populate Anything interface and processes its value (with Jet Sloth's Color Picker plugin).
*
* Plugin Name: GP Populate Anything — Color Picker Choice Template
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
* Description: Adds a custom template row and value processing for "Color Picker" in Populate Anything.
* Author: Gravity Wiz
* Version: 1.0
*/
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add security guard and text domain header
It’s best practice to prevent direct access by checking ABSPATH at the top of the file, and to include a Text Domain (and optionally Domain Path) in the plugin header so translations work correctly.

Example diff:

1a2,5
+ if ( ! defined( 'ABSPATH' ) ) {
+     exit; // Exit if accessed directly.
+ }
15a20,21
+ * Text Domain:   gp-populate-anything
+ * Domain Path:   /languages
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<?php
/**
* Gravity Perks // Populate Anything // Add Custom Template Row for Color Picker
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*
* Instructions Video: https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c
*
* Adds "Color Picker" template row to the Populate Anything interface and processes its value (with Jet Sloth's Color Picker plugin).
*
* Plugin Name: GP Populate Anything — Color Picker Choice Template
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
* Description: Adds a custom template row and value processing for "Color Picker" in Populate Anything.
* Author: Gravity Wiz
* Version: 1.0
*/
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Gravity Perks // Populate Anything // Add Custom Template Row for Color Picker
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*
* Instructions Video: https://www.loom.com/share/c062a781a86242de9f1ebb92492a408c
*
* Adds "Color Picker" template row to the Populate Anything interface and processes its value (with Jet Sloth's Color Picker plugin).
*
* Plugin Name: GP Populate Anything — Color Picker Choice Template
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
* Description: Adds a custom template row and value processing for "Color Picker" in Populate Anything.
* Author: Gravity Wiz
* Version: 1.0
* Text Domain: gp-populate-anything
* Domain Path: /languages
*/

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.

@saifsultanc I made a naming update suggestion, but other than it looks ready to go 💯

…plate for GPPA to work with Jet Sloth Color Picker plugin.
@saifsultanc saifsultanc merged commit f520713 into master May 1, 2025
0 of 3 checks passed
@saifsultanc saifsultanc deleted the saif/add/82217-colorpicker-choice-template branch May 1, 2025 10:22
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