GFPDFHelperFieldsField_Rank

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_Rank.php  
  1. class Field_Rank extends Helper_Abstract_Fields { 
  2.  
  3. /** 
  4. * Return the HTML form data 
  5. * @return array 
  6. * @since 4.0 
  7. */ 
  8. public function form_data() { 
  9.  
  10. $data = []; 
  11. $value = $this->value(); 
  12.  
  13. $data['survey']['rank'][ $this->field->id ] = $value; 
  14.  
  15. return $data; 
  16.  
  17. /** 
  18. * Display the HTML version of this field 
  19. * @param string $value 
  20. * @param bool $label 
  21. * @return string 
  22. * @since 4.0 
  23. */ 
  24. public function html( $value = '', $label = true ) { 
  25.  
  26. $html = GFCommon::get_lead_field_display( $this->field, $this->get_value(), $this->entry['currency'] ); 
  27. $html = apply_filters( 'gform_entry_field_value', $html, $this->field, $this->entry, $this->form ); 
  28.  
  29. return parent::html( $html ); 
  30.  
  31. /** 
  32. * Get the standard GF value of this field 
  33. * @return string|array 
  34. * @since 4.0 
  35. */ 
  36. public function value() { 
  37. if ( $this->has_cache() ) { 
  38. return $this->cache(); 
  39.  
  40. /** Process field */ 
  41. $items = explode( ', ', $this->get_value() ); 
  42.  
  43. $value = []; 
  44.  
  45. /** Loop through each of the user-selected items */ 
  46. foreach ( $items as $rating ) { 
  47.  
  48. /** Loop through the total choices */ 
  49. foreach ( $this->field->choices as $choice ) { 
  50. if ( trim( $choice['value'] ) == trim( $rating ) ) { 
  51. $value[] = esc_html( $choice['text'] ); 
  52. break; /** exit inner loop as soon as found */ 
  53.  
  54. $this->cache( $value ); /** for backwards compatbility we'll wrap it in an array */ 
  55.  
  56. return $this->cache();