GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-field-password.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file class-gravityview-field-password.php
4  * @package GravityView
5  * @subpackage includes\fields
6  */
7 
9 
10  var $name = 'password';
11 
12  var $is_searchable = false;
13 
14  /** @see GF_Field_Password */
15  var $_gf_field_class_name = 'GF_Field_Password';
16 
17  var $group = 'advanced';
18 
19  public function __construct() {
20  $this->label = esc_html__( 'Password', 'gk-gravityview' );
21 
22  $this->add_hooks();
23 
24  parent::__construct();
25 
26  add_filter( 'gravityview/field/password/value', array( $this, 'get_value' ), 10, 6 );
27  }
28 
29  /**
30  * Filter the value of the field, future.
31  *
32  * @since 2.0
33  *
34  * @param mixed $value The value of the field.
35  * @param \GV\Field $field The field as seen by future.
36  * @param \GV\View $view The view requested in.
37  * @param \GV\Source $source The data source (form).
38  * @param \GV\Entry $entry The entry.
39  * @param \GV\Request $request The request context.
40  *
41  * @return mixed $value The filtered value.
42  */
43  public function get_value( $value, $field, $view, $source, $entry, $request ) {
44  /** Passwords should never be exposed. */
45  return '';
46  }
47 
48 
49  /**
50  * Add filters to modify the front-end label and the Add Field label
51  *
52  * @since 1.17
53  *
54  * @return void
55  */
56  function add_hooks() {
57  add_filter( 'gravityview/common/get_form_fields', array( $this, 'add_form_fields' ), 10, 3 );
58 
59  add_filter( 'gravityview/template/field_label', array( $this, 'field_label' ), 10, 4 );
60  }
61 
62  /**
63  * Use the GV Admin Field label for the Password field instead of the per-input setting
64  *
65  * @since 1.17
66  *
67  * @param string $label Field label HTML
68  * @param array $field GravityView field array
69  * @param array $form Gravity Forms form array
70  * @param array $entry Gravity Forms entry array
71  *
72  * @return string If a custom field label isn't set, return the field label for the password field
73  */
74  function field_label( $label = '', $field = array(), $form = array(), $entry = array() ){
75 
76  // If using a custom label, no need to fetch the parent label
77  if( ! is_numeric( $field['id'] ) || ! empty( $field['custom_label'] ) ) {
78  return $label;
79  }
80 
81  $field_object = GFFormsModel::get_field( $form, $field['id'] );
82 
83  if( $field_object && 'password' === $field_object->type ) {
84  $label = $field['label'];
85  }
86 
87  return $label;
88  }
89 
90  /**
91  * If a form has list fields, add the columns to the field picker
92  *
93  * @since 1.17
94  *
95  * @param array $fields Associative array of fields, with keys as field type
96  * @param array $form GF Form array
97  * @param bool $include_parent_field Whether to include the parent field when getting a field with inputs
98  *
99  * @return array $fields with list field columns added, if exist. Unmodified if form has no list fields.
100  */
101  function add_form_fields( $fields = array(), $form = array(), $include_parent_field = true ) {
102 
103  foreach ( $fields as $key => $field ) {
104  if( 'password' === $field['type'] ) {
105 
106  // The Enter Password input
107  if( floor( $key ) === floatval( $key ) ) {
108 
109  if( ! empty( $field['parent'] ) ) {
110  $field['label'] = $field['parent']->label;
111  $field['adminOnly'] = $field['parent']->adminOnly;
112  $field['adminLabel'] = $field['parent']->adminLabel;
113  // Don't show as a child input
114  unset( $field['parent'] );
115  }
116 
117  $fields[ $key ] = $field;
118  } else {
119  // The Confirm Password input
120  unset( $fields[ $key ] );
121  }
122  }
123  }
124 
125  return $fields;
126  }
127 
128 }
129 
Modify field settings by extending this class.
field_label( $label='', $field=array(), $form=array(), $entry=array())
Use the GV Admin Field label for the Password field instead of the per-input setting.
add_hooks()
Add filters to modify the front-end label and the Add Field label.
if(gravityview() ->plugin->is_GF_25()) $form
add_form_fields( $fields=array(), $form=array(), $include_parent_field=true)
If a form has list fields, add the columns to the field picker.
$entry
Definition: notes.php:27
get_value( $value, $field, $view, $source, $entry, $request)
Filter the value of the field, future.