Skip to content

Commit

Permalink
gpnf-admin-merge-tag-modifier-template.php: Migrated from `experime…
Browse files Browse the repository at this point in the history
…ntal` folder.
  • Loading branch information
sbassah authored Jan 7, 2025
1 parent 56e6249 commit b6ed5b9
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions gp-nested-forms/gpnf-admin-merge-tag-modifier-template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Allow :admin modifier in {all_fields} merge tag to affect displayed nested form.
* IMPORTANT: Make sure the file name is "nested-entries-detail.php".
* Usage: Place this file in your current active theme structure.
*
* Experimental Snippet 🧪
*
* @var array $nested_fields An array of GF_Field objects.
* @var array $nested_form The form object of the nested form.
* @var array $nested_field_ids An array of nested field IDs.
* @var array $entries An array of child entries submitted from the current Nested Form field.
* @var array $labels An array of labels used in this template.
* @var array $actions An array of HTML strings used to display field actions.
* @var array $args An array of arguments passed to the template.
*/
?>
<div class="gpnf-nested-entries-container gpnf-entry-view ginput_container">

<table class="gpnf-nested-entries">

<thead>
<tr>
<?php foreach ( $nested_fields as $nested_field ) : ?>
<th class="gpnf-field-<?php echo $nested_field['id']; ?>">
<?php
if ( rgar( $args, 'modifiers' ) && strpos( $args['modifiers'], 'admin' ) !== false ) {
$nested_field->set_context_property( 'use_admin_label', true );
}
?>
<?php echo GFCommon::get_label( $nested_field ); ?>
</th>
<?php endforeach; ?>
<th class="gpnf-row-actions">&nbsp;</th>
</tr>
</thead>

<tbody>
<?php foreach ( $entries as $entry ) : ?>
<?php $field_values = gp_nested_forms()->get_entry_display_values( $entry, $nested_form, $nested_field_ids ); ?>
<tr>
<?php
foreach ( $nested_fields as $nested_field ) :
$field_value = rgars( $field_values, "{$nested_field['id']}/label" );
?>
<td class="gpnf-field"
data-heading="<?php echo GFCommon::get_label( $nested_field ); ?>"
data-value="<?php echo esc_attr( $field_value ); ?>">
<?php echo $field_value; ?>
</td>
<?php endforeach; ?>
<!-- The whitespace below matters. Using CSS :empty to hide when link is not output. -->
<td class="gpnf-row-actions"><?php if ( ! empty( $labels['view_entry'] ) ) : ?>
<a href="<?php echo gp_nested_forms()->get_entry_url( $entry['id'], $nested_form['id'] ); ?>">
<?php echo $labels['view_entry']; ?>
</a>
<?php endif; ?></td>
</tr>
<?php endforeach; ?>
</tbody>

</table>

<div class="gpnf-actions">
<?php echo implode( ' | ', $actions ); ?>
</div>

</div>

0 comments on commit b6ed5b9

Please sign in to comment.