1 | <?php |
||
14 | class Internal_Field extends Field { |
||
15 | /** |
||
16 | * @var \GravityView_Field|false The backing GravityView field (old). False if none exists. |
||
17 | */ |
||
18 | public $field; |
||
19 | |||
20 | /** |
||
21 | * Create self from a configuration array. |
||
22 | * |
||
23 | * @param array $configuration The configuration array. |
||
24 | * @see \GV\Field::as_configuration() |
||
25 | * @internal |
||
26 | * @since 2.0 |
||
27 | * |
||
28 | * @return \GV\Internal_Field|null The field implementation or null on error. |
||
29 | */ |
||
30 | 59 | public static function from_configuration( $configuration ) { |
|
31 | |||
32 | 59 | if ( empty( $configuration['id'] ) || ! is_string( $configuration['id'] ) ) { |
|
33 | gravityview()->log->error( 'Invalid configuration[id] supplied.' ); |
||
34 | return null; |
||
35 | } |
||
36 | |||
37 | 59 | $field = self::by_id( $configuration['id'] ); |
|
38 | |||
39 | 59 | $field->update_configuration( $configuration ); |
|
40 | |||
41 | 59 | return $field; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * Get a \GV\GF_Field from an internal Gravity Forms field ID. |
||
46 | * |
||
47 | * @param int $field_id The internal Gravity Forms field ID. |
||
48 | * |
||
49 | * @return \GV\Internal_Field|null The requested field or null if not found. |
||
50 | */ |
||
51 | 78 | public static function by_id( $field_id ) { |
|
64 | |||
65 | /** |
||
66 | * Retrieve the label for this field. |
||
67 | * |
||
68 | * @param \GV\View $view The view for this context if applicable. |
||
69 | * @param \GV\Source $source The source (form) for this context if applicable. |
||
70 | * @param \GV\Entry $entry The entry for this context if applicable. |
||
71 | * @param \GV\Request $request The request for this context if applicable. |
||
72 | * |
||
73 | * @return string The label for this field. |
||
74 | */ |
||
75 | 27 | public function get_label( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) { |
|
76 | |||
77 | 27 | if ( ! $this->show_label ) { |
|
78 | return ''; |
||
79 | } |
||
80 | |||
81 | 27 | if ( $label = parent::get_label( $view, $source, $entry, $request ) ) { |
|
82 | 1 | return $label; |
|
83 | } |
||
84 | |||
85 | 26 | if ( $this->label ) { |
|
86 | 22 | return $this->label; |
|
87 | } |
||
88 | |||
89 | 6 | return $this->field ? $this->field->label : ''; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Retrieve the value for this field. |
||
94 | * |
||
95 | * Requires the \GV\Entry in this implementation. |
||
96 | * |
||
97 | * @param \GV\View $view The view for this context if applicable. |
||
98 | * @param \GV\Source $source The source (form) for this context if applicable. |
||
99 | * @param \GV\Entry $entry The entry for this context if applicable. |
||
100 | * @param \GV\Request $request The request for this context if applicable. |
||
101 | * |
||
102 | * @return mixed The value for this field. |
||
103 | */ |
||
104 | 60 | public function get_value( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) { |
|
125 | } |
||
126 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: