PDF for GravityView Hooks – gfpdf_gv_table_field_use_div
Description
Overrides the <table> or <div> markup choice for one field in the Single Entry PDF for a Table or DataTables View. The rules for the automatic choice are on gfpdf_gv_table_div_field_types.
Return true for <div> markup or false for <table> markup. Forcing <table> markup on a field whose value contains paragraphs, lists or nested tables can break its layout.
Version
This hook was introduced in PDF for GravityView 2.0.
Arguments
The following arguments are passed to functions that use this hook:
$use_div | bool
trueto wrap the field in<div>markup,falsefor<table>markup.- The default value is the result of the automatic detection.
$field | \GV\Field
- The View field being rendered.
$field->IDis the form field ID and$field->typeis the field type.
$value | string
- The field's rendered HTML, as it will appear in the PDF.
$view | \GV\View
- The View the PDF is being generated for.
$view_entry | \GV\Entry
- The entry being rendered.
Usage
Keep field 7 on the <table> path, so CSS written for td.value still applies:
add_filter( 'gfpdf_gv_table_field_use_div', function( $use_div, $field, $value, $view, $view_entry ) {
if ( (string) $field->ID === '7' ) {
return false;
}
return $use_div;
}, 10, 5 );
Use <div> markup for any field whose value contains an image:
add_filter( 'gfpdf_gv_table_field_use_div', function( $use_div, $field, $value, $view, $view_entry ) {
if ( stripos( $value, '<img' ) !== false ) {
return true;
}
return $use_div;
}, 10, 5 );
Source Code
This filter is located in src/Pdf/Templates/gravityview-single-entry-table-template.php of the PDF for GravityView extension.