|
1 | 1 | <?php |
2 | 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 | | - * Display visual source and target field indicators next to field labels in the form editor. |
| 3 | + * We're no longer using the experimental folder for experimental snippets. 🚧 |
| 4 | + * You can now find the snippet here: |
| 5 | + * https://github.com/gravitywiz/snippet-library/blob/master/gp-copy-cat/gpcc-field-indicators.php |
7 | 6 | */ |
8 | | -add_filter( 'gform_field_content', function( $content, $field ) { |
9 | | - |
10 | | - if ( ! GFCommon::is_form_editor() || ! class_exists( 'GP_Copy_Cat' ) || ! $field->formId ) { |
11 | | - return $content; |
12 | | - } |
13 | | - |
14 | | - $gpcc = new GP_Copy_Cat( 'fake.php' ); |
15 | | - $gpcc_fields = $gpcc->get_copy_cat_fields( GFAPI::get_form( $field->formId ) ); |
16 | | - if ( empty( $gpcc_fields ) ) { |
17 | | - return $content; |
18 | | - } |
19 | | - |
20 | | - if ( ! has_action( 'admin_footer', 'gpcc_field_indicator_styles' ) ) { |
21 | | - add_filter( 'admin_footer', 'gpcc_field_indicator_styles' ); |
22 | | - } |
23 | | - |
24 | | - $mappings = array(); |
25 | | - foreach ( $gpcc_fields as $_mappings ) { |
26 | | - $mappings = array_merge( $mappings, $_mappings ); |
27 | | - } |
28 | | - |
29 | | - $spans = array(); |
30 | | - |
31 | | - foreach ( $mappings as $mapping ) { |
32 | | - if ( $field->id == $mapping['source'] ) { |
33 | | - $spans['source'] = '<span class="gpcc-source gw-field-indicator">GPCC: Source</span>'; |
34 | | - } |
35 | | - if ( $field->id == $mapping['target'] ) { |
36 | | - $spans['target'] = '<span class="gpcc-target gw-field-indicator">GPCC: Target</span>'; |
37 | | - } |
38 | | - if ( $field->id == $mapping['trigger'] ) { |
39 | | - $spans['trigger'] = '<span class="gpcc-trigger gw-field-indicator">GPCC: Trigger</span>'; |
40 | | - } |
41 | | - } |
42 | | - |
43 | | - $search = '<\/label>|<\/legend>'; |
44 | | - $replace = sprintf( '%s\0', implode( '', $spans ) ); |
45 | | - $content = preg_replace( "/$search/", $replace, $content, 1 ); |
46 | | - |
47 | | - return $content; |
48 | | -}, 11, 2 ); |
49 | | - |
50 | | -function gpcc_field_indicator_styles() { |
51 | | - ?> |
52 | | - <style> |
53 | | - .gw-field-indicator { |
54 | | - margin: 0 0 0 0.6875rem; |
55 | | - background-color: #ecedf8; |
56 | | - border: 1px solid #d5d7e9; |
57 | | - border-radius: 40px; |
58 | | - font-size: 0.6875rem; |
59 | | - font-weight: 600; |
60 | | - padding: 0.1125rem 0.4625rem; |
61 | | - vertical-align: text-top; |
62 | | - position: relative; |
63 | | - top: 3px; |
64 | | - } |
65 | | - .gw-field-indicator + .gw-field-indicator { |
66 | | - margin-left: 0.3725rem; |
67 | | - } |
68 | | - .gpcc-source, .gpcc-target, .gpcc-trigger { |
69 | | - color: #274524; |
70 | | - background-color: #edf8ec; |
71 | | - border-color: #d7e8d5; |
72 | | - } |
73 | | - </style> |
74 | | - <?php |
75 | | -} |
0 commit comments