Skip to content

Commit dffb872

Browse files
committed
Merge branch 'release/1.4.3'
2 parents 3cc1d2b + 07283fb commit dffb872

4 files changed

Lines changed: 132 additions & 76 deletions

File tree

includes/Pods_GF.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ private function __construct( $pod, $form_id ) {
156156
// Pod object
157157
if ( is_object( $pod ) ) {
158158
$this->pod =& $pod;
159-
$this->id =& $this->pod->id;
159+
$this->id = $this->pod->id;
160160
}
161161
// Pod name
162162
elseif ( ! is_array( $pod ) ) {
163163
$this->pod = pods( $pod );
164-
$this->id =& $this->pod->id;
164+
$this->id = $this->pod->id;
165165
}
166166
// GF entry
167167
elseif ( isset( $pod['id'] ) ) {
@@ -1877,19 +1877,18 @@ public static function gf_dynamic_select( $form, $ajax = false, $dynamic_selects
18771877
return $form;
18781878
}
18791879

1880-
if ( isset( self::$actioned[$form['id']] ) && in_array( __FUNCTION__, self::$actioned[$form['id']] ) ) {
1880+
if ( isset( self::$actioned[ $form['id'] ] ) && in_array( __FUNCTION__, self::$actioned[ $form['id'] ], true ) ) {
18811881
return $form;
1882-
}
1883-
elseif ( ! isset( self::$actioned[$form['id']] ) ) {
1884-
self::$actioned[$form['id']] = array();
1882+
} elseif ( ! isset( self::$actioned[ $form['id'] ] ) ) {
1883+
self::$actioned[ $form['id'] ] = array();
18851884
}
18861885

1887-
self::$actioned[$form['id']][] = __FUNCTION__;
1886+
self::$actioned[ $form['id'] ][] = __FUNCTION__;
18881887

18891888
$field_keys = array();
18901889

18911890
foreach ( $form['fields'] as $k => $field ) {
1892-
$field_keys[(string) $field['id']] = $k;
1891+
$field_keys[ (string) $field['id'] ] = $k;
18931892
}
18941893

18951894
// Dynamic Select handler
@@ -2187,6 +2186,8 @@ public static function gf_prepopulate( $form, $ajax = false, $prepopulate = null
21872186

21882187
$basic_array = isset( $prepopulate['fields'][0] );
21892188

2189+
// @todo Need to know list of Pod field >> GF field for name/address/etc fields.
2190+
21902191
// Prepopulate values
21912192
foreach ( $prepopulate['fields'] as $field => $field_options ) {
21922193
if ( $basic_array && is_string( $field_options ) ) {
@@ -2394,7 +2395,12 @@ public static function gf_prepopulate( $form, $ajax = false, $prepopulate = null
23942395
} elseif ( 'address' === $gf_field->type ) {
23952396
// @todo Figure out what to do for address values
23962397
} elseif ( 'name' === $gf_field->type ) {
2397-
// @todo Figure out what to do for name values
2398+
// @todo This is beginning logic to setup mapping for each input, but needs value overrides.
2399+
foreach ( $gf_field->inputs as $k => $input ) {
2400+
$input['name'] = 'pods_gf_field_' . str_replace( '.', '_', $input['id'] );
2401+
2402+
$gf_field->inputs[ $k ] = $input;
2403+
}
23982404
} elseif ( 'chainedselect' === $gf_field->type ) {
23992405
// @todo Figure out what to do for chained select values
24002406
} elseif ( 'checkbox' === $gf_field->type ) {
@@ -2459,7 +2465,7 @@ public static function gf_prepopulate( $form, $ajax = false, $prepopulate = null
24592465
$value_override = implode( ',', $value_override_chunked );
24602466
}
24612467

2462-
$_GET['pods_gf_field_' . $field] = pods_slash( $value_override );
2468+
$_GET[ 'pods_gf_field_' . $field ] = pods_slash( $value_override );
24632469
}
24642470

24652471
$post_value_override = null;
@@ -2472,7 +2478,7 @@ public static function gf_prepopulate( $form, $ajax = false, $prepopulate = null
24722478
$post_value_override = maybe_serialize( $post_value_override );
24732479
}
24742480

2475-
$_POST['input_' . $field] = pods_slash( $post_value_override );
2481+
$_POST[ 'input_' . $field ] = pods_slash( $post_value_override );
24762482
}
24772483
}
24782484

@@ -3162,15 +3168,13 @@ public static function gf_read_only_pre_submission( $form ) {
31623168
* @return array $form GF Form array
31633169
*/
31643170
public function _gf_pre_render( $form, $ajax = false ) {
3165-
31663171
$form = $this->setup_form( $form );
31673172

31683173
if ( empty( $this->options ) ) {
31693174
return $form;
31703175
}
31713176

31723177
return $form;
3173-
31743178
}
31753179

31763180
/**
@@ -3182,15 +3186,13 @@ public function _gf_pre_render( $form, $ajax = false ) {
31823186
* @return string Form HTML
31833187
*/
31843188
public function _gf_get_form_filter( $form_string, $form ) {
3185-
3186-
if ( isset( self::$actioned[$form['id']] ) && in_array( __FUNCTION__, self::$actioned[$form['id']] ) ) {
3189+
if ( isset( self::$actioned[ $form['id'] ] ) && in_array( __FUNCTION__, self::$actioned[ $form['id'] ], true ) ) {
31873190
return $form_string;
3188-
}
3189-
elseif ( ! isset( self::$actioned[$form['id']] ) ) {
3190-
self::$actioned[$form['id']] = array();
3191+
} elseif ( ! isset( self::$actioned[ $form['id'] ] ) ) {
3192+
self::$actioned[ $form['id'] ] = array();
31913193
}
31923194

3193-
self::$actioned[$form['id']][] = __FUNCTION__;
3195+
self::$actioned[ $form['id'] ][] = __FUNCTION__;
31943196

31953197
// Cleanup $_GET
31963198
if ( $_GET ) {

includes/Pods_GF_Addon.php

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -843,36 +843,36 @@ public function populate_related_items_tooltip( $tooltips ) {
843843
}
844844

845845
/**
846-
*
846+
* Init integration.
847847
*/
848848
public function init() {
849-
850849
parent::init();
851850

852-
if ( $this->is_gravityforms_supported() ) {
853-
// Handle normal forms.
854-
add_filter( 'gform_pre_render', array( $this, '_gf_pre_render' ), 9, 2 );
855-
add_filter( 'gform_admin_pre_render', array( $this, '_gf_pre_render' ), 9, 1 );
856-
add_filter( 'gform_pre_process', array( $this, '_gf_pre_process' ) );
851+
if ( ! $this->is_gravityforms_supported() ) {
852+
return;
853+
}
857854

858-
// Handle merge tags
859-
add_filter( 'gform_custom_merge_tags', array( $this, '_gf_custom_merge_tags' ), 10, 2 );
860-
add_filter( 'gform_merge_tag_data', array( $this, '_gf_add_merge_tags' ), 10, 3 );
861-
add_filter( 'gform_replace_merge_tags', array( $this, '_gf_replace_merge_tags' ), 10, 2 );
855+
// Handle normal forms.
856+
add_filter( 'gform_pre_render', array( $this, '_gf_pre_render' ), 9, 3 );
857+
add_filter( 'gform_admin_pre_render', array( $this, '_gf_pre_render' ), 9, 1 );
858+
add_filter( 'gform_pre_process', array( $this, '_gf_pre_process' ) );
862859

863-
// Handle entry detail edits.
864-
add_action( 'gform_pre_entry_detail', array( $this, '_gf_pre_entry_detail' ), 10, 2 );
865-
add_action( 'check_admin_referer', array( $this, '_check_admin_referer' ), 10, 2 );
866-
add_action( 'gform_entry_detail_content_before', array( $this, '_gf_entry_detail_content_before' ), 10, 2 );
860+
// Handle merge tags
861+
add_filter( 'gform_custom_merge_tags', array( $this, '_gf_custom_merge_tags' ), 10, 2 );
862+
add_filter( 'gform_merge_tag_data', array( $this, '_gf_add_merge_tags' ), 10, 3 );
863+
add_filter( 'gform_replace_merge_tags', array( $this, '_gf_replace_merge_tags' ), 10, 2 );
867864

868-
// Handle entry updates.
869-
add_action( 'gform_post_update_entry', array( $this, '_gf_post_update_entry' ), 9, 2 );
870-
add_action( 'gform_after_update_entry', array( $this, '_gf_after_update_entry' ), 9, 3 );
865+
// Handle entry detail edits.
866+
add_action( 'gform_pre_entry_detail', array( $this, '_gf_pre_entry_detail' ), 10, 2 );
867+
add_action( 'check_admin_referer', array( $this, '_check_admin_referer' ), 10, 2 );
868+
add_action( 'gform_entry_detail_content_before', array( $this, '_gf_entry_detail_content_before' ), 10, 2 );
871869

872-
// Handle Payment Add-on callbacks.
873-
add_action( 'gform_action_pre_payment_callback', array( $this, '_gf_action_pre_payment_callback' ), 10, 2 );
874-
}
870+
// Handle entry updates.
871+
add_action( 'gform_post_update_entry', array( $this, '_gf_post_update_entry' ), 9, 2 );
872+
add_action( 'gform_after_update_entry', array( $this, '_gf_after_update_entry' ), 9, 3 );
875873

874+
// Handle Payment Add-on callbacks.
875+
add_action( 'gform_action_pre_payment_callback', array( $this, '_gf_action_pre_payment_callback' ), 10, 2 );
876876
}
877877

878878
/**
@@ -893,7 +893,7 @@ public function process_feed( $feed, $entry, $form ) {
893893
return null;
894894
}
895895

896-
$form = $this->_gf_pre_render( $form, $entry );
896+
$form = $this->_gf_pre_render( $form, false, $entry );
897897

898898
/** @var Pods_GF $pods_gf */
899899
$pods_gf = $this->pods_gf[ $feed['id'] ];
@@ -974,7 +974,7 @@ public function _gf_pre_entry_detail( $form, $entry ) {
974974
remove_action( 'check_admin_referer', array( $this, '_check_admin_referer' ) );
975975
remove_action( 'gform_entry_detail_content_before', array( $this, '_gf_entry_detail_content_before' ) );
976976

977-
$this->_gf_pre_render( $form, $entry, true );
977+
$this->_gf_pre_render( $form, false, $entry, true );
978978

979979
}
980980

@@ -1004,7 +1004,7 @@ public function _check_admin_referer( $action, $result ) {
10041004
*/
10051005
public function _gf_entry_detail_content_before( $form, $entry ) {
10061006

1007-
$this->_gf_pre_render( $form, $entry, true );
1007+
$this->_gf_pre_render( $form, false, $entry, true );
10081008

10091009
}
10101010

@@ -1013,7 +1013,11 @@ public function _gf_entry_detail_content_before( $form, $entry ) {
10131013
*
10141014
* @return mixed
10151015
*/
1016-
public function _gf_pre_render( $form, $entry = null, $admin_edit = false ) {
1016+
public function _gf_pre_render( $form, $ajax = false, $entry = null, $admin_edit = false ) {
1017+
// Bad form / form ID.
1018+
if ( empty( $form ) ) {
1019+
return $form;
1020+
}
10171021

10181022
static $setup = array();
10191023

@@ -1071,52 +1075,58 @@ public function _gf_pre_render( $form, $entry = null, $admin_edit = false ) {
10711075
* @var GF_Field $gf_field
10721076
*/
10731077
foreach ( $form['fields'] as $gf_field ) {
1074-
if ( ! empty( $gf_field->pods_populate_related_items ) ) {
1075-
$pod_field = null;
1078+
if ( empty( $gf_field->pods_populate_related_items ) ) {
1079+
//continue;
1080+
}
10761081

1077-
foreach ( $pod_fields as $k => $field_options ) {
1078-
if ( (string) $gf_field->id === (string) $field_options['gf_field'] ) {
1079-
$pod_field = $field_options['field'];
1080-
}
1081-
}
1082+
$pod_field = null;
10821083

1083-
if ( empty( $pod_field ) ) {
1084-
continue;
1084+
foreach ( $pod_fields as $k => $field_options ) {
1085+
if ( (string) $gf_field->id === (string) $field_options['gf_field'] ) {
1086+
$pod_field = $field_options['field'];
10851087
}
1088+
}
10861089

1087-
$pod_field_options = $pod_obj->fields( $pod_field );
1090+
if ( empty( $pod_field ) ) {
1091+
continue;
1092+
}
10881093

1089-
// Override limit for autocomplete
1090-
$object_params = array(
1091-
'limit' => -1,
1092-
);
1094+
$pod_field_options = $pod_obj->fields( $pod_field );
10931095

1094-
$data = PodsForm::field_method( $pod_field_options['type'], 'get_field_data', $pod_field_options, array(), $object_params );
1096+
if ( empty( $pod_field_options ) ) {
1097+
continue;
1098+
}
10951099

1096-
if ( empty( $data ) ) {
1097-
continue;
1098-
}
1100+
// Override limit for autocomplete
1101+
$object_params = array(
1102+
'limit' => -1,
1103+
);
10991104

1100-
if ( isset( $data[''] ) ) {
1101-
unset( $data[''] );
1102-
}
1105+
$data = PodsForm::field_method( $pod_field_options['type'], 'get_field_data', $pod_field_options, array(), $object_params );
1106+
1107+
if ( empty( $data ) ) {
1108+
continue;
1109+
}
11031110

1104-
$select_text = pods_v( $pod_field_options['type'] . '_select_text', $pod_field_options['options'], __( '-- Select One --', 'pods' ), true );
1111+
if ( isset( $data[''] ) ) {
1112+
unset( $data[''] );
1113+
}
11051114

1106-
$options = array(
1107-
'options' => $data,
1108-
);
1115+
$select_text = pods_v( $pod_field_options['type'] . '_select_text', $pod_field_options['options'], __( '-- Select One --', 'pods' ), true );
11091116

1110-
if ( $select_text ) {
1111-
$options['select_text'] = $select_text;
1112-
}
1117+
$options = array(
1118+
'options' => $data,
1119+
);
11131120

1114-
$dynamic_selects[ $gf_field->id ] = $options;
1121+
if ( $select_text ) {
1122+
$options['select_text'] = $select_text;
11151123
}
1124+
1125+
$dynamic_selects[ $gf_field->id ] = $options;
11161126
}
11171127

11181128
if ( ! empty( $dynamic_selects ) ) {
1119-
$form = Pods_GF::gf_dynamic_select( $form, $dynamic_selects );
1129+
$form = Pods_GF::gf_dynamic_select( $form, false, $dynamic_selects );
11201130
}
11211131
}
11221132

pods-gravity-forms.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Pods Gravity Forms Add-On
44
Plugin URI: https://pods.io/
55
Description: Integration with Gravity Forms (https://www.gravityforms.com/); Provides a UI for mapping a Form's submissions into a Pod
6-
Version: 1.4.2
6+
Version: 1.4.3
77
Author: Pods Framework Team
88
Author URI: https://pods.io/about/
99
Text Domain: pods-gravity-forms
@@ -167,3 +167,41 @@ function pods_gf_add_related_objects_forms( $name = null, $value = null, $option
167167
return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id );
168168

169169
}
170+
171+
/**
172+
* Register add-on with Pods Freemius connection.
173+
*/
174+
function pods_gravity_forms_freemius() {
175+
try {
176+
fs_dynamic_init( array(
177+
'id' => '5754',
178+
'slug' => 'pods-gravity-forms',
179+
'type' => 'plugin',
180+
'public_key' => 'pk_1aaaee6bf8963f2077405e84f2ac5',
181+
'is_premium' => false,
182+
'has_paid_plans' => false,
183+
'is_org_compliant' => true,
184+
'parent' => array(
185+
'id' => '5347',
186+
'slug' => 'pods',
187+
'public_key' => 'pk_737105490825babae220297e18920',
188+
'name' => 'Pods',
189+
),
190+
'menu' => array(
191+
'slug' => 'pods-settings',
192+
'contact' => false,
193+
'support' => false,
194+
'affiliation' => false,
195+
'account' => true,
196+
'pricing' => false,
197+
'addons' => true,
198+
'parent' => array(
199+
'slug' => 'pods',
200+
),
201+
),
202+
) );
203+
} catch ( \Exception $exception ) {
204+
return;
205+
}
206+
}
207+
add_action( 'pods_freemius_init', 'pods_gravity_forms_freemius' );

readme.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Donate link: https://pods.io/friends-of-pods/
44
Tags: pods, gravity forms, form mapping
55
Requires at least: 4.6
66
Tested up to: 5.4
7-
Stable tag: 1.4.2
7+
Requires PHP: 5.4
8+
Stable tag: 1.4.3
89
License: GPLv2 or later
910
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1011

@@ -114,6 +115,11 @@ function my_column_row_override( $row, $columns, $form, $gf_field, $options, $re
114115

115116
== Changelog ==
116117

118+
= 1.4.3 - March 17th, 2020 =
119+
120+
* Fixed: Prepopulate handling for relationship fields.
121+
* Fixed: Prevent errors when form doesn't exist by the time it gets to our hook.
122+
117123
= 1.4.2 - March 2nd, 2020 =
118124

119125
* Fixed: Ajax handling for various callbacks that hook into `gform_pre_render`.

0 commit comments

Comments
 (0)