GFPDFHelperFieldsField_Post_Tags

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_Post_Tags.php  
  1. class Field_Post_Tags 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_Post_Tags ) { 
  15. throw new Exception( '$field needs to be in instance of GF_Field_Post_Tags' ); 
  16.  
  17. /** call our parent method */ 
  18. parent::__construct( $field, $entry, $gform, $misc ); 
  19.  
  20. /** 
  21. * Standardised method for returning the field's correct $form_data['field'] keys 
  22. * @return array 
  23. * @since 4.0 
  24. */ 
  25. public function form_data() { 
  26.  
  27. $value = implode( ', ', $this->value() ); 
  28. $label = GFFormsModel::get_label( $this->field ); 
  29. $field_id = (int) $this->field->id; 
  30. $data = []; 
  31.  
  32. /** Add HTML output */ 
  33. $data[ $field_id . '.' . $label ] = $value; 
  34. $data[ $field_id ] = $value; 
  35. $data[ $label ] = $value; 
  36.  
  37. return [ 'field' => $data ]; 
  38.  
  39. /** 
  40. * Display the HTML version of this field 
  41. * @param string $value 
  42. * @param bool $label 
  43. * @return string 
  44. * @since 4.0 
  45. */ 
  46. public function html( $value = '', $label = true ) { 
  47. $value = implode( ', ', $this->value() ); 
  48.  
  49. return parent::html( $value ); 
  50.  
  51. /** 
  52. * Get the standard GF value of this field 
  53. * @return string|array 
  54. * @since 4.0 
  55. */ 
  56. public function value() { 
  57. if ( $this->has_cache() ) { 
  58. return $this->cache(); 
  59.  
  60. $value = explode( ', ', $this->get_value() ); /** get tags and turn into array */ 
  61. $value = array_map( 'trim', $value ); 
  62. $value = array_map( 'esc_html', $value ); 
  63.  
  64. $this->cache( $value ); 
  65.  
  66. return $this->cache();