GFPDFHelperFieldsField_Select

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_Select.php  
  1. class Field_Select 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_Select ) { 
  15. throw new Exception( '$field needs to be in instance of GF_Field_Select' ); 
  16.  
  17. /** call our parent method */ 
  18. parent::__construct( $field, $entry, $gform, $misc ); 
  19.  
  20. /** 
  21. * Return the HTML form data 
  22. * @return array 
  23. * @since 4.0 
  24. */ 
  25. public function form_data() { 
  26.  
  27. $value = $this->value(); 
  28. $label = GFFormsModel::get_label( $this->field ); 
  29. $data = []; 
  30.  
  31. /** Standadised Format */ 
  32. $data['field'][ $this->field->id . '.' . $label ] = $value['value']; 
  33. $data['field'][ $this->field->id ] = $value['value']; 
  34. $data['field'][ $label ] = $value['value']; 
  35.  
  36. /** Name Format */ 
  37. $data['field'][ $this->field->id . '.' . $label . '_name' ] = $value['label']; 
  38. $data['field'][ $this->field->id . '_name' ] = $value['label']; 
  39. $data['field'][ $label . '_name' ] = $value['label']; 
  40.  
  41. return $data; 
  42.  
  43. /** 
  44. * Display the HTML version of this field 
  45. * @param string $value 
  46. * @param bool $label 
  47. * @return string 
  48. * @since 4.0 
  49. */ 
  50. public function html( $value = '', $label = true ) { 
  51. $data = $this->value(); 
  52.  
  53. $value = apply_filters( 'gfpdf_show_field_value', false ); /** Set to `true` to show a field's value instead of the label */ 
  54. $output = ( $value ) ? $data['value'] : $data['label']; 
  55.  
  56. return parent::html( $output ); 
  57.  
  58. /** 
  59. * Get the standard GF value of this field 
  60. * @return array 
  61. * @since 4.0 
  62. */ 
  63. public function value() { 
  64. if ( $this->has_cache() ) { 
  65. return $this->cache(); 
  66.  
  67. $label = esc_html( GFCommon::selection_display( $this->get_value(), $this->field, '', true ) ); 
  68. $value = esc_html( GFCommon::selection_display( $this->get_value(), $this->field ) ); 
  69.  
  70. /** return value / label as an array */ 
  71. $this->cache( [ 
  72. 'value' => $value,  
  73. 'label' => $label,  
  74. ] ); 
  75.  
  76. return $this->cache();