PDF for GravityView Hooks – gfpdf_gv_table_div_field_types
Description
Sets which field types always use <div> markup instead of <table> markup in the PDF for a Table or DataTables View.
From 2.0, the Single Entry PDF for a Table or DataTables View wraps each field in its own <table> or <div> element, instead of giving it a row in one big table. The markup for each is shown in Upgrading Your CSS from 1.x.
The PDF engine handles paragraphs, lists and other block-level content badly inside a table cell. A field uses <div> markup when:
- Its type is in this list.
- It's a Paragraph field with the rich text editor turned on.
- It's a Custom Content field that uses the
{all_fields},{all_fields_display_empty}or{pricing_fields}merge tag. - Its rendered value contains a block-level tag, such as
<p>,<div>,<ul>,<table>or a heading.
Everything else uses <table> markup, so CSS written for td.label and td.value still applies to most fields.
You rarely need this filter, because block-level output is detected from the HTML. Add a field type when you want every field of that type on the <div> path, whatever its value. To decide field by field, use gfpdf_gv_table_field_use_div, which runs after this list is checked.
The same list is used by the Multiple Entries PDF for a Table or DataTables View. A column whose field type is in the list (or matches the Paragraph or Custom Content rules above) switches that PDF to the float layout. See gfpdf_gv_multiple_entries_layout.
Version
This hook was introduced in PDF for GravityView 2.0.
Arguments
The following arguments are passed to functions that use this hook:
$field_types | array
- The field types that always use
<div>markup, matched against the field'stype. - The default value is
[ 'gravityview_view', 'html', 'repeater' ](GravityView's View field, and Gravity Forms' HTML and Repeater fields).
$view | \GV\View
- The View the PDF is being generated for.
$view_entry | \GV\Entry or \GV\Entry_Collection
- A
\GV\Entryfor a Single Entry PDF. - A
\GV\Entry_Collectionfor a Multiple Entries PDF.
Usage
Put every List field on the <div> path:
add_filter( 'gfpdf_gv_table_div_field_types', function( $field_types, $view, $view_entry ) {
$field_types[] = 'list';
return $field_types;
}, 10, 3 );
Put HTML fields back on the <table> path for View 885. An HTML field whose content contains block-level tags still uses <div> markup:
add_filter( 'gfpdf_gv_table_div_field_types', function( $field_types, $view, $view_entry ) {
if ( (int) $view->ID === 885 ) {
$field_types = array_values( array_diff( $field_types, [ 'html' ] ) );
}
return $field_types;
}, 10, 3 );
Source Code
This filter is located in src/Pdf/Layout/BlockLevel.php of the PDF for GravityView extension.