|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Gravity Forms // All Fields Template // Template: Collapsible |
| 4 | + * https://gravitywiz.com/gravity-forms-all-fields-template/ |
| 5 | + * |
| 6 | + * Adds support for a collapsible template with All Fields Template. |
| 7 | + * |
| 8 | + * Instructions: |
| 9 | + * |
| 10 | + * 1. Ensure you have All Fields Template installled. |
| 11 | + * https://gravitywiz.com/gravity-forms-all-fields-template/ |
| 12 | + * |
| 13 | + * 2. Install this snippet. No code configuration required. |
| 14 | + * https://gravitywiz.com/documentation/managing-snippets/#where-do-i-put-snippets |
| 15 | + * |
| 16 | + * 3. Enable the collapsible template on any {all_fields} merge tag. |
| 17 | + * {all_fields:template[collapsible]} |
| 18 | + */ |
| 19 | +add_filter( 'gwaft_template_output', function( $content, $slug, $name, $data, $suffixes ) { |
| 20 | + if ( ! in_array( 'collapsible', $suffixes ) ) { |
| 21 | + return $content; |
| 22 | + } |
| 23 | + $pages = $data['form']['pagination']['pages']; |
| 24 | + $page_groups = array(); |
| 25 | + foreach ( $data['items'] as $item ) { |
| 26 | + $page_groups[ $item['field']['pageNumber'] ][] = $item; |
| 27 | + } |
| 28 | + ob_start(); |
| 29 | + ?> |
| 30 | + <style> |
| 31 | + .gwaft-collapsible { |
| 32 | + margin-top: 1rem; |
| 33 | + } |
| 34 | + .gwaft-collapsible details { |
| 35 | + background: var( --gf-color-primary, #2b4cdc ); |
| 36 | + color: white; |
| 37 | + border: 2px solid var( --gf-color-primary, #2b4cdc ); |
| 38 | + border-radius: var( --gf-radius, 3px ); |
| 39 | + padding: 1rem; |
| 40 | + margin-bottom: 1rem; |
| 41 | + } |
| 42 | + .gwaft-collapsible details[open] { |
| 43 | + background: transparent; |
| 44 | + color: inherit; |
| 45 | + } |
| 46 | + .gwaft-collapsible summary { |
| 47 | + outline-width: 0; |
| 48 | + } |
| 49 | + .gwaft-collapsible ul { |
| 50 | + margin: 1rem 0 0; |
| 51 | + padding: 0; |
| 52 | + font-size: 1rem; |
| 53 | + } |
| 54 | + .gwaft-collapsible li { |
| 55 | + display: flex; |
| 56 | + gap: 1rem; |
| 57 | + padding: 1rem; |
| 58 | + border-radius: var( --gf-radius, 3px ); |
| 59 | + } |
| 60 | + .gwaft-collapsible li:nth-child(odd) { |
| 61 | + background: rgb( from var(--gf-color-primary) r g b / 5% ); |
| 62 | + } |
| 63 | + .gwaft-collapsible li span { |
| 64 | + flex: 1; |
| 65 | + } |
| 66 | + </style> |
| 67 | + <div class="gwaft-collapsible"> |
| 68 | + <?php foreach ( $page_groups as $page_number => $page_group ): ?> |
| 69 | + <details> |
| 70 | + <summary><?php echo $pages[ $page_number ] ?></summary> |
| 71 | + <ul> |
| 72 | + <?php foreach( $page_group as $item ): |
| 73 | + ?> |
| 74 | + |
| 75 | + <li> |
| 76 | + <span><?php echo $item['label']; ?></span> |
| 77 | + <span><?php echo $item['value']; ?></span> |
| 78 | + </li> |
| 79 | + |
| 80 | + <?php |
| 81 | + endforeach; ?> |
| 82 | + </ul> |
| 83 | + </details> |
| 84 | + <?php endforeach; ?> |
| 85 | + </div> |
| 86 | + <?php |
| 87 | + return ob_get_clean(); |
| 88 | +}, 10, 5 ); |
0 commit comments