Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions gravity-forms/gw-advanced-merge-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,35 @@ public function handle_field_modifiers( $value, $input_id, $modifier, $field, $r
return rgar( $value_array, $index );
}
break;
case 'all_fields':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am open to different names for this like all_dynamic_entries or something? Curious what @spivurno thinks.

// Only to be applied for GPPA scenarios, where we may using dynamically populated entry ID data.
if ( ! is_callable( 'gp_populate_anything' ) || ! gp_populate_anything()->is_field_dynamically_populated( $field ) ) {
break;
}

// {all_fields} merge tag support needs to get the entry IDs from the raw value.
$entries = json_decode( $raw_value, true );

// loop through each entry ID and get the {all_fields} output.
$output = '';
foreach ( $entries as $entry_id ) {
$entry = GFAPI::get_entry( $entry_id );
$form = GFAPI::get_form( $entry['form_id'] );

// Safety check: Ensure the entry belongs to the same form as the field.
if ( $field->{'gppa-choices-primary-property'} != $entry['form_id'] ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For added security, I'm curious if you could somehow recreate this logic or extract the logic in GPPA into a method that could be re-used: https://github.com/gravitywiz/gp-populate-anything/blob/a924ffcc780cc4bb01c117a194c1fa674fda6193/class-gp-populate-anything.php#L2608-L2644

Alternatively, if it's only used in the context of admins, you could add a security disclaimer to this modifier saying that it should not be used in places where non-admins can see the output of this merge tag modifier.

break;
}

// Get the {all_fields} output for each entry.
$all_fields_output = GFCommon::replace_variables( '{all_fields}', $form, $entry, false, false, false );

$output .= $all_fields_output . '<br>';
}

// if no entries were found, return the original value.
$value = $output ? $output : $value;
break;
}
}

Expand Down
Loading