Skip to main content

PDF for GravityView Hooks – gfpdf_gv_field_star_empty

Description​

Change the empty star image for Survey rating fields. 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 empty star is a gray star outline 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 filled star too with gfpdf_gv_field_star_filled.

Each star is output as <img class="gv-field-survey-star gv-field-survey-star-empty" 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 an empty 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 (a #ccc star outline 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 light blue outline star to pair with a blue filled star:

add_filter( 'gfpdf_gv_field_star_empty', function( $star ) {
$svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" stroke="#9ec2e6" stroke-width="1.5" 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_empty', function( $star, $entry, $field_settings, $gravityview ) {
if ( rgar( $field_settings, 'id' ) == 14 ) {
return get_stylesheet_directory() . '/images/heart-empty.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.