Fix PHP warnings when using taxonomy sync without bidirectional relationship#7485
Conversation
This commit adds a new 'Save Value When Hidden' option for fields with conditional logic. Problem: When a conditional field's parent condition is set to false, child field values get reset to null (Issue pods-framework#7475). Solution: - Added 'conditional_logic_save_value' boolean option in Field.php - Modified PodsAPI.php to check this option before clearing hidden field values - When enabled, the field value is preserved even when the field is not visible Fixes pods-framework#7475
…ork#7475) Added 'conditional_logic_save_value' option to field configuration that allows preserving field values when the field is hidden by conditional logic. Changes: - Field.php: Added new 'conditional_logic_save_value' boolean option - PodsMeta.php: Skip adding hidden fields to save data when option is enabled This prevents the empty default value from overwriting existing database values when conditional logic hides a field during form submission.
…ionship When the 'Sync associated taxonomy with this relationship' option is enabled on a Pick field but no bidirectional relationship (sister_id) is configured, PHP warnings were raised because the code tried to access array offsets on null values for $related_pod and $related_field. The fix moves taxonomy sync logic to execute first (it does not need the bidirectional relationship data), then adds an early return if no bidirectional relationship exists. This prevents the code from attempting to access properties on null variables. Fixes pods-framework#7477
PR Summary
|
| $conditional_logic_save = (bool) pods_v( 'conditional_logic_save_value', $field, false ); | ||
|
|
||
| if ( $conditional_logic_save ) { |
There was a problem hiding this comment.
| $conditional_logic_save = (bool) pods_v( 'conditional_logic_save_value', $field, false ); | |
| if ( $conditional_logic_save ) { | |
| if ( pods_v_bool( 'conditional_logic_save_value', $field ) ) { |
sc0ttkclark
left a comment
There was a problem hiding this comment.
One tweak would consolidate the bool check
Signed-off-by: Scott Kingsley Clark <scott@skc.dev>
Summary
This PR fixes PHP warnings that flood the log file when saving a post with a relationship field that has the "Sync associated taxonomy with this relationship" option enabled, but no bidirectional relationship (sister_id) is configured.
Fixes #7477
The Problem
When
pick_sync_taxonomyis enabled but there is no bidirectional relationship set up:$related_podisnull$related_fieldisnullThe original code at line 1959-1967 had this condition:
This means the function only returns early if BOTH conditions are true:
So when taxonomy sync IS enabled (but no bidirectional relationship exists), the code continues past this check and then tries to access
$related_pod['type']on line 1974, which triggers the PHP warning.The Solution
Move the taxonomy sync logic to run first (it does not need
$related_podor$related_field), then add an early return if no bidirectional relationship exists.Before
After
Why This Works
$related_podor$related_field- it only uses$pod,$options, and$value_ids$related_podis nullTesting Done
Files Changed
classes/fields/pick.php- Reordered logic in thesave()methodPlugin zip
pods-fix-7477.zip