Skip to main content

PDF for GravityView Hooks – gfpdf_gv_field_star_filled

Description​

Change the filled star image for Survey rating fields, such as its color or shape. When a rating field is set to display as Stars in the View editor, the PDF draws one image per choice: filled stars up to the selected rating, then empty stars. The default filled star is an orange star in a gray ring.

The image is used in the Single Entry PDF and the Multiple Entries PDF. To keep the two images matching, change the empty star too with gfpdf_gv_field_star_empty.

Each star is output as <img class="gv-field-survey-star gv-field-survey-star-filled" src="..."> and is 6mm wide. To change the size, target .gv-field-survey-star with gfpdf_gv_template_styles or the View's Additional CSS setting.

Version​

This hook was introduced in PDF for GravityView 0.2.

Arguments​

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

$star | string​

  • The image used for a filled star, placed in the src attribute of an <img> tag.
  • It can be a data URI, an image URL or a path to an image on the server. SVG, PNG and JPG all work.
  • The default value is a base64-encoded SVG data URI (an #ff9800 star inside a #ccc ring).

$entry | \GV\Entry​

  • The entry being rendered.

$field_settings | array​

  • The View field's settings, from \GV\Field::as_configuration(). $field_settings['id'] is the form field ID.

$gravityview | \GV\Template_Context​

  • GravityView's template context for the field. $gravityview->value is the selected rating's value.

Usage​

Use a blue star with no ring:

add_filter( 'gfpdf_gv_field_star_filled', function( $star ) {
$svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#2271b1" d="M12 17.27 18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"/></svg>';

return 'data:image/svg+xml;base64,' . base64_encode( $svg );
} );

Use an image from your theme for field 14 only. A server path saves the PDF engine from fetching the image over HTTP:

add_filter( 'gfpdf_gv_field_star_filled', function( $star, $entry, $field_settings, $gravityview ) {
if ( rgar( $field_settings, 'id' ) == 14 ) {
return get_stylesheet_directory() . '/images/heart-filled.png';
}

return $star;
}, 10, 4 );

Source Code​

This filter is located in src/Pdf/Fields/field-survey-html.php of the PDF for GravityView extension.