Skip to content

Commit 8b4cbc7

Browse files
authored
Update gppa-add-a-custom-choice-template.php
1 parent eeb3ce3 commit 8b4cbc7

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

gp-populate-anything/gppa-add-a-custom-choice-template.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,32 @@
33
* Gravity Perks // Populate Anything // Add A Custom Choice Template
44
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
55
*
6-
* Choice templates allow you to map data to different properties of your Gravity Forms choices. In this example, we
7-
* demonstrate how to create a new template for a theoretical "image" choice property. With this in place, you would
8-
* be able to select a value in the Populate Anything choices UI that is mapped to the "image" property for each choice.
6+
* Choice templates allow you to map data to different properties of your Gravity Forms choices.
7+
*
8+
* In this example, we demonstrate how to create a new template for a theoretical "image" choice property.
9+
* With this in place, you would be able to select a value in the Populate Anything choices UI that is
10+
* mapped to the "image" property for each choice.
911
*/
12+
add_action( 'admin_print_footer_scripts', function () {
13+
if ( ! is_callable( 'GFCommon::is_form_editor' ) || ! GFCommon::is_form_editor() ) {
14+
return;
15+
}
16+
?>
17+
<script>
18+
window.gform.addFilter( 'gppa_template_rows', function (templateRows, field, populate) {
19+
if ( populate !== 'choices' ) {
20+
return templateRows;
21+
}
22+
templateRows.push( {
23+
id: 'image',
24+
label: 'Image',
25+
} );
26+
return templateRows;
27+
} );
28+
</script>
29+
<?php
30+
} );
31+
1032
add_filter( 'gppa_input_choice', function( $choice, $field, $object, $objects ) {
1133
$choice['image'] = gp_populate_anything()->process_template( $field, 'image', $object, 'choices', $objects );
1234
return $choice;

0 commit comments

Comments
 (0)