Skip to content

Commit 4ea0a43

Browse files
authored
gpcc-field-indicators.php: Migrated from experimental folder.
1 parent e21b59b commit 4ea0a43

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Copy Cat // Show Source and Target Field Indicators in Form Editor
4+
* https://gravitywiz.com/documentation/gravity-forms-copy-cat/
5+
*
6+
* Experimental Snippet 🧪
7+
*
8+
* Display visual source and target field indicators next to field labels in the form editor.
9+
*/
10+
add_filter( 'gform_field_content', function( $content, $field ) {
11+
12+
if ( ! GFCommon::is_form_editor() || ! class_exists( 'GP_Copy_Cat' ) || ! $field->formId ) {
13+
return $content;
14+
}
15+
16+
$gpcc = new GP_Copy_Cat( 'fake.php' );
17+
$gpcc_fields = $gpcc->get_copy_cat_fields( GFAPI::get_form( $field->formId ) );
18+
if ( empty( $gpcc_fields ) ) {
19+
return $content;
20+
}
21+
22+
if ( ! has_action( 'admin_footer', 'gpcc_field_indicator_styles' ) ) {
23+
add_filter( 'admin_footer', 'gpcc_field_indicator_styles' );
24+
}
25+
26+
$mappings = array();
27+
foreach ( $gpcc_fields as $_mappings ) {
28+
$mappings = array_merge( $mappings, $_mappings );
29+
}
30+
31+
$spans = array();
32+
33+
foreach ( $mappings as $mapping ) {
34+
if ( $field->id == $mapping['source'] ) {
35+
$spans['source'] = '<span class="gpcc-source gw-field-indicator">GPCC: Source</span>';
36+
}
37+
if ( $field->id == $mapping['target'] ) {
38+
$spans['target'] = '<span class="gpcc-target gw-field-indicator">GPCC: Target</span>';
39+
}
40+
if ( $field->id == $mapping['trigger'] ) {
41+
$spans['trigger'] = '<span class="gpcc-trigger gw-field-indicator">GPCC: Trigger</span>';
42+
}
43+
}
44+
45+
$search = '<\/label>|<\/legend>';
46+
$replace = sprintf( '%s\0', implode( '', $spans ) );
47+
$content = preg_replace( "/$search/", $replace, $content, 1 );
48+
49+
return $content;
50+
}, 11, 2 );
51+
52+
function gpcc_field_indicator_styles() {
53+
?>
54+
<style>
55+
.gw-field-indicator {
56+
margin: 0 0 0 0.6875rem;
57+
background-color: #ecedf8;
58+
border: 1px solid #d5d7e9;
59+
border-radius: 40px;
60+
font-size: 0.6875rem;
61+
font-weight: 600;
62+
padding: 0.1125rem 0.4625rem;
63+
vertical-align: text-top;
64+
position: relative;
65+
top: 3px;
66+
}
67+
.gw-field-indicator + .gw-field-indicator {
68+
margin-left: 0.3725rem;
69+
}
70+
.gpcc-source, .gpcc-target, .gpcc-trigger {
71+
color: #274524;
72+
background-color: #edf8ec;
73+
border-color: #d7e8d5;
74+
}
75+
</style>
76+
<?php
77+
}

0 commit comments

Comments
 (0)