GFPDFHelperFieldsField_Poll

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_Poll.php  
  1. class Field_Poll 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. /** call our parent method */ 
  15. parent::__construct( $field, $entry, $gform, $misc ); 
  16.  
  17. /** 
  18. * Custom Field can be any of the following field types: 
  19. * single line text, paragraph, dropdown, select, number, checkbox, radio, hidden,  
  20. * date, time, phone, website, email, file upload or list 
  21. */ 
  22. $class = $this->misc->get_field_class( $field->inputType ); 
  23.  
  24. try { 
  25. /** check load our class */ 
  26. if ( class_exists( $class ) ) { 
  27.  
  28. /** See https://gravitypdf.com/documentation/v4/gfpdf_field_class/ for more details about these filters */ 
  29. $this->fieldObject = apply_filters( 'gfpdf_field_class', new $class( $field, $entry, $gform, $misc ), $field, $entry, $this->form ); 
  30. $this->fieldObject = apply_filters( 'gfpdf_field_class_' . $field->inputType, $this->fieldObject, $field, $entry, $this->form ); 
  31. } else { 
  32. throw new Exception( 'Class not found' ); 
  33. } catch ( Exception $e ) { 
  34. /** Exception thrown. Load generic field loader */ 
  35. $this->fieldObject = apply_filters( 'gfpdf_field_default_class', new Field_Default( $field, $entry, $gform, $misc ), $field, $entry, $this->form ); 
  36.  
  37. /** 
  38. * Used to check if the current field has a value 
  39. * @since 4.0 
  40. */ 
  41. public function is_empty() { 
  42. return $this->fieldObject->is_empty(); 
  43.  
  44. /** 
  45. * Return the HTML form data 
  46. * @return array 
  47. * @since 4.0 
  48. */ 
  49. public function form_data() { 
  50.  
  51. $data = []; 
  52. $value = $this->value(); 
  53. $field_id = (int) $this->field->id; 
  54. $label = GFFormsModel::get_label( $this->field ); 
  55.  
  56. if ( isset( $value[0] ) ) { 
  57.  
  58. $field = []; 
  59.  
  60. foreach ( $value as $item ) { 
  61. /** For backwards compatibility, we'll wrap these in their own array key */ 
  62. $field[0][] = $item['label']; 
  63. } else { 
  64. $field = ( isset( $value['label'] ) ) ? $value['label'] : ''; 
  65.  
  66. $data[ $field_id . '.' . $label ] = $field; 
  67. $data[ $field_id . '.' . $label . '_name' ] = $field; /** for backwards compatibility */ 
  68. $data[ $field_id ] = $field; 
  69. $data[ $label ] = $field; 
  70.  
  71. return [ 'field' => $data ]; 
  72.  
  73. /** 
  74. * Display the HTML version of this field 
  75. * @param string $value 
  76. * @param bool $label 
  77. * @return string 
  78. * @since 4.0 
  79. */ 
  80. public function html( $value = '', $label = true ) { 
  81. return $this->fieldObject->html(); 
  82.  
  83. /** 
  84. * Get the standard GF value of this field 
  85. * @return string|array 
  86. * @since 4.0 
  87. */ 
  88. public function value() { 
  89. if ( $this->fieldObject->has_cache() ) { 
  90. return $this->cache(); 
  91.  
  92. $value = $this->fieldObject->value(); 
  93.  
  94. $this->fieldObject->cache( $value ); 
  95.  
  96. return $this->fieldObject->cache();