Skip to main content

PDF for GravityView Hooks – gfpdf_gv_template_arguments

Description​

Changes the variables passed to a PDF for GravityView template, or adds your own. Use it to get extra data into a template override without querying for it inside the template.

Each key in the $args array becomes a variable in the template. For example, $args['view'] is also available as $view.

The filter runs once per PDF, for both the Single Entry PDF and the Multiple Entries PDF, just before the template is loaded.

note

When the render cache is on, a cached PDF is served without running the template or this filter. If the data you add changes over time, independent of the entry, the View or its settings, the cached copy is served until it expires. See gfpdf_gv_cache_ttl.

Version​

This hook was introduced in PDF for GravityView 0.1.

Arguments​

The following arguments are passed to functions that use this hook:

$args | array​

  • The variables passed to the PDF template. PDF for GravityView adds these four:
    • view: the \GV\View being rendered.
    • view_entry: a \GV\Entry for a Single Entry PDF, or a \GV\Entry_Collection for a Multiple Entries PDF.
    • view_template: the GravityView template class the layout uses on the website. A \GV\Entry_Template for a Single Entry PDF, or a \GV\View_Template for a Multiple Entries PDF.
    • view_fields: the fields to be rendered, grouped by their zone in the View editor (such as single_table-columns or directory_list-title). Fields removed by gfpdf_gv_field_middleware or the Exclude from PDF? setting are already gone, and gfpdf_gv_view_field has already run.
  • The rest come from Gravity PDF: form_id, lead_id, form, entry, form_data, fields, config, settings and gfpdf. See Gravity PDF's gfpdf_template_args documentation.
  • settings holds the resolved PDF settings from the View's Single Entry PDF or Multiple Entries PDF tab, such as margin, show_title, show_labels and additional_css.
  • A Multiple Entries PDF has no single entry. entry only holds id (every entry ID in the PDF, comma-separated) and form_id, form_data is built from the first entry, and mpdf_writer is added after this filter runs.

$view | \GV\View​

  • The View the PDF is being generated for.

$entry | \GV\Entry or \GV\Entry_Collection​

  • A \GV\Entry for a Single Entry PDF.
  • A \GV\Entry_Collection for a Multiple Entries PDF.

$pdf_settings | array​

Usage​

Pass the current user's display name to your templates as $prepared_for:

add_filter( 'gfpdf_gv_template_arguments', function( $args, $view, $entry, $pdf_settings ) {
$user = wp_get_current_user();

$args['prepared_for'] = $user->exists() ? $user->display_name : '';

return $args;
}, 10, 4 );

Pass the number of entries to Multiple Entries PDF templates only:

add_filter( 'gfpdf_gv_template_arguments', function( $args, $view, $entry, $pdf_settings ) {
if ( $entry instanceof \GV\Entry_Collection ) {
$args['entry_count'] = $entry->count();
}

return $args;
}, 10, 4 );

Source Code​

This filter is located in src/Pdf/Renderer.php of the PDF for GravityView extension.