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 | 19 | public static function from_configuration( $configuration ) { |
|
31 | |||
32 | 19 | if ( empty( $configuration['id'] ) || ! is_string( $configuration['id'] ) ) { |
|
33 | gravityview()->log->error( 'Invalid configuration[id] supplied.' ); |
||
34 | return null; |
||
35 | } |
||
36 | |||
37 | 19 | $field = self::by_id( $configuration['id'] ); |
|
38 | |||
39 | 19 | $field->update_configuration( $configuration ); |
|
40 | |||
41 | 19 | 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 | 33 | 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. Nothing here. |
||
74 | */ |
||
75 | 12 | public function get_label( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) { |
|
76 | 12 | if ( $label = parent::get_label( $view, $source, $entry, $request ) ) { |
|
77 | return $label; |
||
78 | } |
||
79 | |||
80 | 12 | if ( ! $this->show_label ) { |
|
81 | return ''; |
||
82 | } |
||
83 | |||
84 | 12 | return $this->field ? $this->field->label : $this->label; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * Retrieve the value for this field. |
||
89 | * |
||
90 | * Requires the \GV\Entry in this implementation. |
||
91 | * |
||
92 | * @param \GV\View $view The view for this context if applicable. |
||
93 | * @param \GV\Source $source The source (form) for this context if applicable. |
||
94 | * @param \GV\Entry $entry The entry for this context if applicable. |
||
95 | * @param \GV\Request $request The request for this context if applicable. |
||
96 | * |
||
97 | * @return mixed The value for this field. |
||
98 | */ |
||
99 | 26 | public function get_value( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) { |
|
120 | } |
||
121 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.