GFPDFEntryDetail

Add deprecated functionality for generating our standard PDF HTML.

Defined (1)

The class is defined in the following location(s).

/src/deprecated.php  
  1. class GFPDFEntryDetail extends GFPDF_Deprecated_Abstract { 
  2.  
  3. /** 
  4. * First legacy wrapper to generate our PDF HTML layout 
  5. * @param array $form The Gravity Form array 
  6. * @param array $lead The Gravity Form entry 
  7. * @param boolean $allow_display_empty_fields 
  8. * @param boolean $show_html 
  9. * @param boolean $show_page_name 
  10. * @param boolean $return 
  11. * @return string If $return is `true` the generated HTML will be returned 
  12. * @since 3.0 
  13. */ 
  14. public static function lead_detail_grid( $form, $lead, $allow_display_empty_fields = false, $show_html = false, $show_page_name = false, $return = false ) { 
  15. $config = [ 
  16. 'meta' => [ 
  17. 'empty_field' => $allow_display_empty_fields,  
  18. 'return' => $return,  
  19. 'html_field' => $show_html,  
  20. 'page_names' => $show_page_name,  
  21. ],  
  22. ]; 
  23.  
  24. return self::do_lead_detail_grid( $form, $lead, $config ); 
  25.  
  26. /** 
  27. * Second legacy wrapper to generate our PDF HTML layout 
  28. * @param array $form The Gravity Form array 
  29. * @param array $lead The Gravity Form entry 
  30. * @param array $config The PDF Configuration 
  31. * @return string If $config['meta']['echo'] is false the HTML will be returned 
  32. * @since 3.7 
  33. */ 
  34. public static function do_lead_detail_grid( $form, $lead, $config = [] ) { 
  35.  
  36. /** Convert old config values to our new ones */ 
  37. if ( ! isset( $config['meta'] ) ) { 
  38. $config = [ 'meta' => $config ]; 
  39.  
  40. return self::generate_v3_html_structure( $form, $lead, $config['meta'] ); 
  41.  
  42. /** 
  43. * Loop through our form and output the results 
  44. * @param array $form The Gravity Form array 
  45. * @param array $lead The Gravity Form entry 
  46. * @param array $config The PDF Configuration 
  47. * @return array|void 
  48. * @since 4.0 
  49. */ 
  50. public static function generate_v3_html_structure( $form, $lead, $config ) { 
  51.  
  52. /** Setup our variables */ 
  53. $model = GPDFAPI::get_mvc_class( 'Model_PDF' ); 
  54. $products = new Field_v3_Products( new GF_Field(), $lead, GPDFAPI::get_form_class(), GPDFAPI::get_misc_class() ); 
  55. $has_products = false; 
  56. $page_number = 0; 
  57.  
  58. /** Change the standardised HTML field output to be v3 compatible */ 
  59. add_filter( 'gfpdf_field_html_value', [ 'GFPDFEntryDetail', 'legacy_html_format' ], 10, 5 ); 
  60. add_filter( 'gfpdf_field_class', [ 'GFPDFEntryDetail', 'load_legacy_html_classes' ], 10, 3 ); 
  61.  
  62. /** Setup field to return the form data, if needed */ 
  63. $results = [ 
  64. 'title' => '',  
  65. 'field' => [],  
  66. ]; 
  67.  
  68. /** Output the form title */ 
  69. if ( $config['return'] ) { 
  70. $results['title'] = '<h2 id="details" class="default">' . $form['title'] . '</h2>'; 
  71. } else { 
  72. ?> 
  73.  
  74. <?php echo $styles; ?> 
  75. <div id='container'> 
  76. <h2 id='details' class='default'><?php echo $form['title'] ?></h2> 
  77. <?php 
  78.  
  79. /** Loop through our fields and output */ 
  80. foreach ( $form['fields'] as $field ) { 
  81.  
  82. /** Skip any fields with the css class 'exclude' or any hidden fields */ 
  83. if ( strpos( $field->cssClass, 'exclude' ) !== false || GFFormsModel::is_field_hidden( $form, $field, [], $lead ) ) { 
  84. continue; 
  85.  
  86. /** Skip over any product fields, if needed */ 
  87. if ( GFCommon::is_product_field( $field->type ) ) { 
  88. $has_products = true; 
  89. continue; 
  90.  
  91. /** Check if we should display the page names */ 
  92. if ( $config['page_names'] === true && (int) $field->pageNumber !== $page_number && isset( $form['pagination']['pages'][ $page_number ] ) ) { 
  93. if ( $config['return'] ) { 
  94. $results['field'][] = '<h2 id="field-' . $field->id . '" class="default entry-view-page-break">' . $form['pagination']['pages'][ $page_number ] . '</h2>'; 
  95. } else { 
  96. ?> 
  97. <h2 id="field-<?php echo $field->id; ?>" 
  98. class="default entry-view-page-break"><?php echo $form['pagination']['pages'][ $page_number ]; ?></h2> 
  99. <?php 
  100. $page_number++; 
  101.  
  102. /** Output each field type */ 
  103. $input = RGFormsModel::get_input_type( $field ); 
  104. $excluded = [ 'captcha', 'password', 'page' ]; 
  105.  
  106. /** Skip over any fields we don't want to include */ 
  107. if ( in_array( $input, $excluded ) ) { 
  108. continue; 
  109.  
  110. /** Load our class */ 
  111. $class = $model->get_field_class( $field, $form, $lead, $products ); 
  112.  
  113. self::load_legacy_css( $field ); 
  114.  
  115. /** Check if HTML field should be included */ 
  116. if ( $input == 'html' ) { 
  117.  
  118. if ( $config['html_field'] === true ) { 
  119. $html = $class->html(); 
  120.  
  121. if ( $config['return'] ) { 
  122. $results['field'][] = $html; 
  123. } else { 
  124. echo $html; 
  125.  
  126. continue; 
  127.  
  128. /** Only load our HTML if the field is NOT empty, or the 'empty_field' config option is true */ 
  129. if ( $config['empty_field'] === true || ! $class->is_empty() ) { 
  130.  
  131. $html = ( $field->type !== 'section' ) ? $class->html() : $class->html( $config['section_content'] ); 
  132.  
  133. if ( $config['return'] ) { 
  134. $results['field'][] = $html; 
  135. } else { 
  136. echo $html; 
  137.  
  138. /** Output product table, if needed */ 
  139. if ( $has_products && ! $products->is_empty() ) { 
  140. $products = $products->html(); 
  141.  
  142. if ( $config['return'] ) { 
  143. $results['field'][] = $products; 
  144. } else { 
  145. echo $products; 
  146.  
  147. /** Return the HTML structure */ 
  148. if ( $config['return'] ) { 
  149. return $results; 
  150. } else { 
  151. ?> 
  152. </div><!-- Close container --> 
  153. <?php 
  154.  
  155. /** 
  156. * Replaces the v4 HTML structure with the legacy v3 code to prevent backwards compatibility problems 
  157. * @param string $html The original field HTML which we'll be discarding 
  158. * @param string $value The field value 
  159. * @param boolean $show_label 
  160. * @param boolean $label Whether to show or hide the field's label 
  161. * @param object $field 
  162. * @return string 
  163. * @since 4.0 
  164. */ 
  165. public static function legacy_html_format( $html, $value, $show_label, $label, $field ) { 
  166.  
  167. $html = '<div id="field-' . $field->id . '" class="' . $field->cssClass . '">'; 
  168.  
  169. if ( $show_label ) { 
  170. $html .= '<div class="strong">' . $label . '</div>'; 
  171.  
  172. /** If the field value is empty we'll add a non-breaking space to act like a character and maintain proper layout */ 
  173. if ( strlen( trim( $value ) ) === 0 ) { 
  174. $value = ' '; 
  175.  
  176. $html .= '<div class="value">' . $value . '</div>' 
  177. . '</div>'; 
  178.  
  179. return $html; 
  180.  
  181. /** 
  182. * Replace some of our Gravity PDF fields with legacy versions to match the old HTML structure 
  183. * @param object $class The original Gravity PDF field class being processed 
  184. * @param object $field The Gravity Form field object being processed 
  185. * @param array $entry The current Gravity Form array of entry data 
  186. * @return object 
  187. * @since 4.0 
  188. */ 
  189. public static function load_legacy_html_classes( $class, $field, $entry ) { 
  190.  
  191. switch ( get_class( $field ) ) { 
  192. case 'GF_Field_Section': 
  193. $class = new GFPDF\Helper\Fields\Field_v3_Section( $field, $entry, GPDFAPI::get_form_class(), GPDFAPI::get_misc_class() ); 
  194. break; 
  195.  
  196. case 'GF_Field_List': 
  197. $class = new GFPDF\Helper\Fields\Field_v3_List( $field, $entry, GPDFAPI::get_form_class(), GPDFAPI::get_misc_class() ); 
  198. break; 
  199.  
  200. return $class; 
  201.  
  202. /** 
  203. * Our default template used a number of legacy classes. 
  204. * To keep backwards compatible, we will manually assign when needed. 
  205. * @param GF_Field $field The Gravity Form Fields 
  206. * @return void (classes are passed by reference) 
  207. * @since 4.0 
  208. */ 
  209. public static function load_legacy_css( GF_Field $field ) { 
  210. static $counter = 1; 
  211.  
  212. /** Because multiple PDFs can be processed at the same time and will share the same field classes we'll only update the css once */ 
  213. if ( strpos( $field->cssClass, 'gfpdf-field-processed' ) !== false ) { 
  214. return; 
  215.  
  216. /** Add odd / even rows */ 
  217. $field->cssClass = ( $counter++ % 2 ) ? $field->cssClass . ' odd' : ' even'; 
  218.  
  219. switch ( $field->type ) { 
  220. case 'html': 
  221. $field->cssClass .= ' entry-view-html-value'; 
  222. break; 
  223.  
  224. case 'section': 
  225. $field->cssClass .= ' entry-view-section-break-content'; 
  226. break; 
  227.  
  228. default: 
  229. $field->cssClass .= ' entry-view-field-value'; 
  230. break; 
  231.  
  232. $field->cssClass .= ' gfpdf-field-processed'; 
  233.  
  234. /** 
  235. * Get the $form_data array 
  236. * @param array $form The Gravity Form array 
  237. * @param array $lead The Gravity Form entry 
  238. * @return array 
  239. * @since 3.0 
  240. */ 
  241. public static function lead_detail_grid_array( $form, $lead ) { 
  242. $model = GPDFAPI::get_pdf_class( 'model' ); 
  243.  
  244. return $model->get_form_data( $lead ); 
  245.  
  246. /** 
  247. * Generate a standard Gravity Forms product table based on the form / entry data 
  248. * @param array $form The Gravity Form array 
  249. * @param array $lead The Gravity Form entry 
  250. * @return void 
  251. * @since 3.0 
  252. */ 
  253. public static function product_table( $form, $lead ) { 
  254. GPDFAPI::product_table( $lead ); 
  255.  
  256. /** 
  257. * Public method for outputting likert (survey addon field) 
  258. * @param array $form The Gravity Form array 
  259. * @param array $lead The Gravity Form entry 
  260. * @param integer $field_id The field ID to output 
  261. * @return string 
  262. * @since 3.0 
  263. */ 
  264. public static function get_likert( $form, $lead, $field_id ) { 
  265. return GPDFAPI::likert_table( $lead, $field_id, true );