GFPDFHelperFieldsField_Name

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_Name.php  
  1. class Field_Name 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_Name ) ) { 
  15. throw new Exception( '$field needs to be in instance of GF_Field_Name' ); 
  16.  
  17. /** call our parent method */ 
  18. parent::__construct( $field, $entry, $gform, $misc ); 
  19.  
  20. /** 
  21. * Display the HTML version of this field 
  22. * @param string $value 
  23. * @param bool $label 
  24. * @return string 
  25. * @since 4.0 
  26. */ 
  27. public function html( $value = '', $label = true ) { 
  28.  
  29. $value = $this->value(); 
  30.  
  31. /** Backwards compatibility check */ 
  32. if ( is_array( $value ) ) { 
  33. $value = array_filter( $value ); /** remove any empty fields from the array */ 
  34. $value = implode( ' ', $value ); 
  35.  
  36. return parent::html( $value ); 
  37.  
  38. /** 
  39. * Get the standard GF value of this field 
  40. * @return array 
  41. * @since 4.0 
  42. */ 
  43. public function value() { 
  44. if ( $this->has_cache() ) { 
  45. return $this->cache(); 
  46.  
  47. $value = $this->get_value(); 
  48.  
  49. /** backwards compatible - check if the returned results are an array otherwise set to cache and return */ 
  50. if ( ! is_array( $value ) ) { 
  51. $this->cache( esc_html( $value ) ); 
  52.  
  53. return $this->cache(); 
  54.  
  55. $value = [ 
  56. 'prefix' => rgget( $this->field->id . '.2', $value ),  
  57. 'first' => rgget( $this->field->id . '.3', $value ),  
  58. 'middle' => rgget( $this->field->id . '.4', $value ),  
  59. 'last' => rgget( $this->field->id . '.6', $value ),  
  60. 'suffix' => rgget( $this->field->id . '.8', $value ),  
  61. ]; 
  62.  
  63. $value = array_map( 'esc_html', $value ); 
  64.  
  65. $this->cache( $value ); 
  66.  
  67. return $this->cache();