Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spivurno/3a3b92bf32824a414c87c23bbf5ca335 to your computer and use it in GitHub Desktop.
Save spivurno/3a3b92bf32824a414c87c23bbf5ca335 to your computer and use it in GitHub Desktop.
Gravity Perks // GP Nested Forms // Display Table Format for All Fields
<?php
/**
* WARNING! THIS SNIPPET MAY BE OUTDATED.
* The latest version of this snippet can be found in the Gravity Wiz Snippet Library:
* https://github.com/gravitywiz/snippet-library/blob/master/gp-nested-forms/gpnf-display-child-entries-table-format.php
*/
/**
* Gravity Perks // GP Nested Forms // Display Table Format for All Fields
* http://gravitywiz.com/documentation/gravity-forms-nested-forms/
*
* Add "gpnf_table" as a modifier to the {all_fields} merge tag to enable this functionality.
*
* Examples:
*
* {all_fields:gpnf_table}
* {all_fields:nohidden,gpnf_table}
*/
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifiers, $field, $raw_value ) {
if ( ! is_callable( 'gp_nested_forms' ) || $field->type != 'form' || $value === false || strpos( $modifiers, 'gpnf_table' ) === false ) {
return $value;
}
// Adds support for :filter modifier on Nested Form field merge tags but not {all_fields}.
$nested_field_ids = $field->gpnfFields;
if ( function_exists( 'gw_all_fields_template' ) ) {
$_modifiers = gw_all_fields_template()->parse_modifiers( $modifiers );
if( $_modifiers['filter'] ) {
$nested_field_ids = is_array( $_modifiers['filter'] ) ? $_modifiers['filter'] : array( $_modifiers['filter'] );
}
}
$template = new GP_Template( gp_nested_forms() );
$nested_form = GFAPI::get_form( rgar( $field, 'gpnfForm' ) );
$args = array(
'template' => 'nested-entries-detail',
'field' => $field,
'nested_form' => GFAPI::get_form( rgar( $field, 'gpnfForm' ) ),
'modifiers' => $modifiers,
'nested_fields' => gp_nested_forms()->get_fields_by_ids( $nested_field_ids, $nested_form ),
'entries' => gp_nested_forms()->get_entries( $raw_value ),
'actions' => array(),
'nested_field_ids' => $nested_field_ids,
'labels' => array( 'view_entry' => '' )
);
$value = $template->parse_template(
array(
sprintf( '%s-%s-%s.php', $args['template'], $nested_form['id'], $field->id ),
sprintf( '%s-%s.php', $args['template'], $nested_form['id'] ),
sprintf( '%s.php', $args['template'] ),
), true, false, $args
);
return $value;
}, 12, 5 );
<?php
/**
* WARNING! THIS SNIPPET MAY BE OUTDATED.
* The latest version of this snippet can be found in the Gravity Wiz Snippet Library:
* https://github.com/gravitywiz/snippet-library/blob/master/gp-nested-forms/gpnf-display-child-entries-table-format.php
*/
/**
* Gravity Perks // GP Nested Forms // Display Table Format for All Fields
* http://gravitywiz.com/documentation/gravity-forms-nested-forms/
* MODIFIED: Show *all* child fields.
*/
add_action( 'init', function () {
if ( !is_callable( 'gp_nested_forms' ) ) {
return;
}
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifiers, $field, $raw_value ) {
if ( $field->type != 'form' || $value === false ) {
return $value;
}
$nested_form = GFAPI::get_form( rgar( $field, 'gpnfForm' ) );
// Adds support for :filter modifier on Nested Form field merge tags but not {all_fields}.
$nested_field_ids = wp_list_pluck( $nested_form['fields'], 'id' );
if ( function_exists( 'gw_all_fields_template' ) ) {
$_modifiers = gw_all_fields_template()->parse_modifiers( $modifiers );
if ( $_modifiers['filter'] ) {
$nested_field_ids = is_array( $_modifiers['filter'] ) ? $_modifiers['filter'] : array( $_modifiers['filter'] );
}
}
$template = new GP_Template( gp_nested_forms() );
$nested_form = GFAPI::get_form( rgar( $field, 'gpnfForm' ) );
$args = array(
'template' => 'nested-entries-detail',
'field' => $field,
'nested_form' => $nested_form,
'modifiers' => $modifiers,
'nested_fields' => gp_nested_forms()->get_fields_by_ids( $nested_field_ids, $nested_form ),
'entries' => gp_nested_forms()->get_entries( $raw_value ),
'actions' => array(),
'nested_field_ids' => $nested_field_ids,
'labels' => array( 'view_entry' => '' )
);
$value = $template->parse_template(
array(
sprintf( '%s-%s-%s.php', $args['template'], $nested_form['id'], $field->id ),
sprintf( '%s-%s.php', $args['template'], $nested_form['id'] ),
sprintf( '%s.php', $args['template'] ),
), true, false, $args
);
return $value;
}, 12, 5 );
} );
@frankdage
Copy link

Hello, how do I implement this please. I mean I want to see all form views with child entries just like gravityforms displays in their entries on the frontend with probably a shortcode. How do I go about this please.

@klaasbpoel
Copy link

Thanks for this great piece of code, one question, how can I align the headers to the left?
GravityForm

@spivurno
Copy link
Author

spivurno commented Dec 6, 2020

@klaasbpoel If you an output styles, try adding this:

.gpnf-nested-entries thead th { text-align: left; }

@klaasbpoel
Copy link

Thanks, figured it out and works perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment