GFPDFHelperFieldsField_Section

Controls the display and output of a Gravity Form field.

Defined (1)

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

/src/helper/fields/Field_Section.php  
  1. class Field_Section extends Helper_Abstract_Fields { 
  2.  
  3. /** 
  4. * Check the appropriate variables are parsed in send to the parent construct 
  5. * @param object $field The GF_Field_* Object 
  6. * @param array $entry The Gravity Forms Entry 
  7. * @param \GFPDF\Helper\Helper_Abstract_Form $gform 
  8. * @param \GFPDF\Helper\Helper_Misc $misc 
  9. * @throws Exception 
  10. * @since 4.0 
  11. */ 
  12. public function __construct( $field, $entry, Helper_Abstract_Form $gform, Helper_Misc $misc ) { 
  13.  
  14. if ( ! is_object( $field ) || ! $field instanceof GF_Field_Section ) { 
  15. throw new Exception( '$field needs to be in instance of GF_Field_Section' ); 
  16.  
  17. /** call our parent method */ 
  18. parent::__construct( $field, $entry, $gform, $misc ); 
  19.  
  20. /** 
  21. * Used to check if the current field has a value 
  22. * @since 4.0 
  23. */ 
  24. public function is_empty() { 
  25.  
  26. /** Run default checks to see if section break contains fields with values */ 
  27. if ( GFCommon::is_section_empty( $this->field, $this->form, $this->entry ) ) { 
  28. return true; 
  29.  
  30. /** Run our own checks against the fields to test for issues */ 
  31. $fields = GFCommon::get_section_fields( $this->form, $this->field->id ); 
  32. $PDF_model = GPDFAPI::get_mvc_class( 'Model_PDF' ); 
  33. $products = new Field_Products( new GF_Field(), $this->entry, $this->gform, $this->misc ); 
  34.  
  35. $empty = true; 
  36. foreach ( $fields as $field ) { 
  37. if ( 'section' !== $field->type ) { 
  38. $class = $PDF_model->get_field_class( $field, $this->form, $this->entry, $products ); 
  39. if ( ! $class->is_empty() ) { 
  40. $empty = false; 
  41. break; 
  42.  
  43. /** Our custom empty checks determined the fields in the section break are infact empty */ 
  44. if ( $empty ) { 
  45. return true; 
  46.  
  47. return false; 
  48.  
  49. /** 
  50. * Return the HTML form data 
  51. * @return array 
  52. * @since 4.0 
  53. */ 
  54. public function form_data() { 
  55.  
  56. $data = []; 
  57.  
  58. $data['section_break'][ $this->field->id ] = $this->value(); 
  59.  
  60. return $data; 
  61.  
  62. /** 
  63. * Display the HTML version of this field 
  64. * @param string $value 
  65. * @param bool $label 
  66. * @return string 
  67. * @since 4.0 
  68. */ 
  69. public function html( $value = '', $label = true ) { 
  70. /** sanitize the HTML */ 
  71. $section = $this->value(); /** allow the same HTML as per the post editor */ 
  72.  
  73. $html = '<div id="field-' . $this->field->id . '" class="gfpdf-section-title gfpdf-field '. $this->field->cssClass .'">'; 
  74. $html .= '<h3>' . $section['title'] . '</h3>'; 
  75.  
  76. if ( ! empty( $value ) ) { 
  77. $html .= '<div id="field-' . $this->field->id . '-desc" class="gfpdf-section-description gfpdf-field">' . $section['description'] . '</div>'; 
  78.  
  79. $html .= '</div>'; 
  80.  
  81. /** 
  82. * See https://gravitypdf.com/documentation/v4/gfpdf_field_section_break_html/ for more information about this filter 
  83. * @since 4.1 
  84. */ 
  85. return apply_filters( 'gfpdf_field_section_break_html',  
  86. $html,  
  87. $section['title'],  
  88. $section['description'],  
  89. $value,  
  90. $this->field,  
  91. $this->form,  
  92. $this->entry,  
  93. $this 
  94. ); 
  95.  
  96. /** 
  97. * Get the standard GF value of this field 
  98. * @return string|array 
  99. * @since 4.0 
  100. */ 
  101. public function value() { 
  102. if ( $this->has_cache() ) { 
  103. return $this->cache(); 
  104.  
  105. $this->cache( [ 
  106. 'title' => esc_html( $this->field->label ),  
  107. 'description' => wp_kses_post( $this->field->description ),  
  108. ] ); 
  109.  
  110. return $this->cache();