GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gv-field-internal.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * The internal \GF_Field field object wrapper.
11  *
12  * Used for custom content fields, etc.
13  */
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  public static function from_configuration( $configuration ) {
31 
32  if ( empty( $configuration['id'] ) || ! is_string( $configuration['id'] ) ) {
33  gravityview()->log->error( 'Invalid configuration[id] supplied for internal field: {id}', array( 'data' => $configuration, 'id' => \GV\Utils::get( $configuration, 'id' ) ) );
34  return null;
35  }
36 
37  $field = self::by_id( $configuration['id'] );
38 
39  $field->update_configuration( $configuration );
40 
41  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  public static function by_id( $field_id ) {
52  $field = new self();
53  $field->ID = $field_id;
54  $field->type = $field->ID;
55 
56  /**
57  * Retrieve the internal backing field (old for now)
58  * @todo switch to future subclasses
59  */
61 
62  return $field;
63  }
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  public function get_label( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) {
76 
77  if ( ! $this->show_label ) {
78  return '';
79  }
80 
81  if ( $label = parent::get_label( $view, $source, $entry, $request ) ) {
82  return $label;
83  }
84 
85  if ( $this->label ) {
86  return $this->label;
87  }
88 
89  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  public function get_value( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) {
105  if ( ! $entry || ! is_a( $entry, '\GV\Entry' ) ) {
106  gravityview()->log->error( '$entry is not a valid \GV\Entry instance' );
107  return null;
108  }
109 
110  /**
111  * @todo Implement in subclasses, once available.
112  *
113  * For example the "content" field will be empty here. It's
114  * value is actually currently retrieved inside ...
115  *
116  * *drumroll*
117  *
118  * A TEMPLATE :)
119  */
120  $value = Utils::get( $entry->as_entry(), $this->ID );
121 
122  /** Apply parent filters. */
123  return $this->get_value_filters( $value, $view, $source, $entry, $request );
124  }
125 }
If this file is called directly, abort.
If this file is called directly, abort.
If this file is called directly, abort.
static from_configuration( $configuration)
Create self from a configuration array.
If this file is called directly, abort.
static by_id( $field_id)
Get a from an internal Gravity Forms field ID.
If this file is called directly, abort.
If this file is called directly, abort.
gravityview()
The main GravityView wrapper function.
get_label(View $view=null, Source $source=null, Entry $entry=null, Request $request=null)
Retrieve the label for this field.
get_value(View $view=null, Source $source=null, Entry $entry=null, Request $request=null)
Retrieve the value for this field.
$entry
Definition: notes.php:27
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
Definition: time.php:22
static get_instance( $field_name)