PDF for GravityView Hooks – gfpdf_gv_view_field
Description
Changes a View field's settings for the PDF only, such as a different label, an extra CSS class or a link turned off. The filter receives each \GV\Field before it's rendered, and the PDF uses the field you return. The View and the website aren't changed.
It runs for every field in both the Single Entry PDF and the Multiple Entries PDF, after gfpdf_gv_field_middleware has removed any fields that won't be shown.
An alias targets one field type:
Alias
gfpdf_gv_view_field_{$field_type}: replace{$field_type}with a field type, such asemail,phone,textarea,fileuploadorcustom. It runs straight aftergfpdf_gv_view_field.
PDF for GravityView uses the gfpdf_gv_view_field_phone alias to stop phone numbers printing as tel: links.
Version
This hook was introduced in PDF for GravityView 0.1.
Arguments
The following arguments are passed to functions that use this hook:
$field | \GV\Field
- The View field about to be rendered.
- Change it with
$field->update_configuration( [ 'setting' => 'value' ] ), which merges your values into the field's existing settings. Use the keys GravityView saves for the field, such ascustom_label,custom_class,show_labelandshow_as_link. - Always return the field, changed or not.
$field_entry | \GV\Entry or null
- For a Single Entry PDF, the entry the field belongs to. If the View joins forms with GravityView's Multiple Forms extension, it's the entry from the field's own form.
- For a Multiple Entries PDF,
null. Fields are prepared once for the whole PDF, so you can't change a field for one row.
$field_form | \GV\GF_Form
- The form the field belongs to.
$view | \GV\View
- The View the PDF is being generated for.
$context | \GV\Template_Context
- GravityView's template context for the field.
$context->fieldis the field and$context->viewis the View. - On a Multiple Entries PDF,
$context->entriesholds the\GV\Entry_Collectionbeing rendered.
Usage
Give field 5 a different label in the PDF:
add_filter( 'gfpdf_gv_view_field', function( $field, $field_entry, $field_form, $view, $context ) {
if ( (string) $field->ID === '5' ) {
$field->update_configuration( [ 'custom_label' => 'Applicant signature (as submitted)' ] );
}
return $field;
}, 10, 5 );
Add a CSS class to every field on View 885's Multiple Entries PDF, so you can style them with gfpdf_gv_template_styles:
add_filter( 'gfpdf_gv_view_field', function( $field, $field_entry, $field_form, $view, $context ) {
if ( (int) $view->ID === 885 && $field_entry === null ) {
$field->update_configuration( [ 'custom_class' => trim( $field->custom_class . ' pdf-compact' ) ] );
}
return $field;
}, 10, 5 );
Source Code
This filter is located in src/Pdf/Renderer.php of the PDF for GravityView extension.