5 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
21 private $configuration = array();
28 public $position =
'';
59 public $custom_label =
'';
73 public $custom_class =
'';
91 public $show_as_link =
false;
99 public $search_filter =
false;
122 return array_merge( array(
124 'label' => $this->label,
125 'show_label' => $this->show_label ?
'1' :
'0',
126 'custom_label' => $this->custom_label,
127 'custom_class' => $this->custom_class,
128 'only_loggedin' => $this->cap ?
'1' :
'0',
129 'only_loggedin_cap' => $this->cap,
130 'search_filter' => $this->search_filter ?
'1' :
'0',
131 'show_as_link' => $this->show_as_link ?
'1' :
'0',
132 ), $this->configuration );
144 final public static function get( $source,
$args ) {
145 if ( ! is_string( $source ) || ! class_exists( $source ) ) {
146 gravityview()->log->error(
'{source} class not found', array(
'source' => $source ) );
150 if ( ! method_exists( $source,
'get_field' ) ) {
151 gravityview()->log->error(
'{source} does not appear to be a valid \GV\Source subclass (get_field method missing)', array(
'source' => $source ) );
155 return call_user_func_array( array( $source,
'get_field' ), is_array(
$args ) ?
$args : array(
$args ) );
169 if ( empty( $configuration[
'id'] ) ) {
171 gravityview()->log->error(
'Trying to get field from configuration without a field ID.', array(
'data' => $configuration ) );
172 $field->update_configuration( $configuration );
177 if ( version_compare( phpversion(),
'5.4',
'>=' ) ) {
178 $trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 );
180 $trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
183 if ( $trace[
'function'] ==
'from_configuration' && $trace[
'class'] == __CLASS__ ) {
185 gravityview()->log->error(
'Infinite loop protection tripped. Returning default class here.' );
186 $field->update_configuration( $configuration );
191 $field_class = is_numeric( $configuration[
'id'] ) ?
'\GV\GF_Field' :
'\GV\Internal_Field';
198 $field_class = apply_filters(
'gravityview/field/class', $field_class, $configuration );
200 if ( ! class_exists( $field_class ) || ! method_exists( $field_class,
'from_configuration' ) ) {
202 gravityview()->log->error(
'Class {field_class}::from_configuration does not exist.', array(
'field_class' => $field_class,
'data' => $configuration ) );
203 $field->update_configuration( $configuration );
208 $field = $field_class::from_configuration( $configuration );
212 gravityview()->log->error(
'Could not configure {field_class} with given configuration.', array(
'field_class' => __CLASS__,
'data' => $configuration ) );
213 $field->update_configuration( $configuration );
229 $configuration = wp_parse_args( $configuration, $this->as_configuration() );
231 if ( $this->ID != $configuration[
'id'] ) {
233 gravityview()->log->warning(
'ID is being changed for {field_class} instance, but implementation is not. Use ::from_configuration instead', array(
'field_class', __CLASS__ ) );
236 $this->ID = $configuration[
'id'];
237 $this->label = $configuration[
'label'];
238 $this->show_label = $configuration[
'show_label'] ==
'1';
239 $this->custom_label = $configuration[
'custom_label'];
240 $this->custom_class = $configuration[
'custom_class'];
241 $this->cap = $configuration[
'only_loggedin'] ==
'1' ? $configuration[
'only_loggedin_cap'] :
'';
242 $this->search_filter = $configuration[
'search_filter'] ==
'1';
243 $this->show_as_link = $configuration[
'show_as_link'] ==
'1';
246 $shared_configuration_keys = array(
247 'id',
'label',
'show_label',
'custom_label',
'custom_class',
248 'only_loggedin' ,
'only_loggedin_cap',
'search_filter',
'show_as_link',
252 foreach ( $configuration as $key =>
$value ) {
253 if ( ! in_array( $key, $shared_configuration_keys ) ) {
254 $this->configuration[ $key ] =
$value;
271 if ( ! $this->show_label ) {
276 if ( ! empty( $this->custom_label ) ) {
277 return \GravityView_API::replace_variables( $this->custom_label, $source ? $source->form ? : null : null,
$entry ?
$entry->as_entry() : null );
296 return $this->get_value_filters( null, $view, $source,
$entry, $request );
321 $value = apply_filters(
"gravityview/field/{$this->type}/value",
$value, $this, $view, $source,
$entry, $request );
333 return apply_filters(
'gravityview/field/value',
$value, $this, $view, $source,
$entry, $request );
352 return apply_filters(
'gravityview/field/is_visible', ( ! $this->cap || \
GVCommon::has_cap( $this->cap ) ), $this, $view );
365 if ( isset( $this->configuration[ $key ] ) ) {
366 return $this->configuration[ $key ];
383 return isset( $this->configuration[ $key ] );
If this file is called directly, abort.
static from_configuration( $configuration)
Create self from a configuration array.
get_value(View $view=null, Source $source=null, Entry $entry=null, Request $request=null)
Retrieve the value for this field.
get_value_filters( $value, View $view=null, Source $source=null, Entry $entry=null, Request $request=null)
Apply all the required filters after get_value() was called.
If this file is called directly, abort.
as_configuration()
Return an array of the old format as used by callers of GVCommon:get_directory_fields() for example...
If this file is called directly, abort.
__get( $key)
Get one of the extra configuration keys via property accessors.
__isset( $key)
Is this set?
If this file is called directly, abort.
If this file is called directly, abort.
gravityview()
The main GravityView wrapper function.
update_configuration( $configuration)
Update configuration.
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
get_label(View $view=null, Source $source=null, Entry $entry=null, Request $request=null)
Retrieve the label for this field.
is_visible( $view=null)
Whether or not this field is visible.