When rendering PDFs, we split the Gravity Form fields display into its own class, which all extend our common abstract class
GFPDF\Helper\Helper_Abstract_Fields (yes, we use namespaces). This filter makes it easy to customise the output of individual fields types by allowing you to overriding or extend the field's class.
The most likely things you'll want to override in a field's class is the
html() method, as it controls the retrieval of the field's entry information and the HTML output, respectively. However, you can completely change all properties of a field if you desire.
In the usage section, we show you how to override an existing field's
value() method to change the output. But for a more in-depth look at how to extend the
GFPDF\Helper\Helper_Abstract_Fields class, we recommend you review the field classes found in
You can also use the filter
gfpdf_field_class_$type, where type refers to the Gravity Form field type (textarea, select, signature etc).
$class | object
- The current field class loaded. These classes are located in
$field | array
- The current Gravity Form field being processed.
$entry | array
- The raw Gravity Form Entry array.
$form | array
- The current Gravity Form array
The following snippet shows you how to use the filter to override the Textarea class. The actual filter is easy to use but you'll also need to create a separate file for your field:
Alternatively we could have used the
gfpdf_field_class_$type filter and removed the IF statement:
And here's the accompanying
Prefix_Allcaps_Textarea_Field.php file which should be in the same directory as the file the
gfpdf_field_class filter above is placed:
It's worth noting that developers who add new fields to Gravity Forms don't need to use this filter to switch out the class. You just need to create a class that extends
GFPDF\Helper\Helper_Abstract_Fields and include it during the
init action. Just make sure you adhere to the appropriate naming convention – see
Helper_Misc::get_field_class($type) for an example of the correct class name (when using the
gfpdf_field_class filter above you don't need to worry about adhering to a specific naming convention).
This filter is located in the
Model_PDF::get_field_class() method of