From d600bc878753bbf6613873ea3755143288fb220f Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Fri, 8 Jun 2018 18:03:50 -0500 Subject: [PATCH 1/7] Update inline docs for pick field selected logic Docs for logic fixes in #5014 and #5017 --- classes/fields/pick.php | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/classes/fields/pick.php b/classes/fields/pick.php index 6d6c2b546f..8fbe55ed35 100644 --- a/classes/fields/pick.php +++ b/classes/fields/pick.php @@ -1298,25 +1298,37 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ // Determine if this is a selected item $selected = false; - if ( is_array( $args->value ) ) { - if ( ! isset( $args->value[0] ) ) { - $keys = array_map( 'strval', array_keys( $args->value ) ); + $values = array(); - if ( in_array( (string) $item_id, $keys, true ) ) { - $selected = true; - } + // If we have values, let's cast them. + if ( ! empty( $args->value ) ) { + // The value may be a single non-array value. + $values = (array) $args->value; + } + + // If the value array has keys as IDs, let's get the keys from the values instead. + if ( ! isset( $values[0] ) ) { + // Get values from keys. + $key_values = array_keys( $values ); + + // Cast key values in array as string. + $key_values = array_map( 'strval', $key_values ); + + // Let's check to see if the current $item_id matches any key values. + if ( in_array( (string) $item_id, $key_values, true ) ) { + $selected = true; } + } - if ( ! $selected ) { - // Cast values in array as string. - $args->value = array_map( 'strval', $args->value ); + // If we do not have a key match, the normal values may still match. + if ( ! $selected ) { + // Cast values in array as string. + $values = array_map( 'strval', $values ); - if ( in_array( (string) $item_id, $args->value, true ) ) { - $selected = true; - } + // Let's check to see if the current $item_id matches any values. + if ( in_array( (string) $item_id, $values, true ) ) { + $selected = true; } - } elseif ( (string) $item_id === (string) $args->value ) { - $selected = true; } $item = array( From 5ea73907da34a4b4dc28e96a47e81dac43e2cc12 Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Fri, 8 Jun 2018 18:10:06 -0500 Subject: [PATCH 2/7] Update pick.php --- classes/fields/pick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/fields/pick.php b/classes/fields/pick.php index 8fbe55ed35..a11d192e34 100644 --- a/classes/fields/pick.php +++ b/classes/fields/pick.php @@ -1306,7 +1306,7 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ $values = (array) $args->value; } - // If the value array has keys as IDs, let's get the keys from the values instead. + // If the value array has keys as IDs, let's check for matches from the keys first. if ( ! isset( $values[0] ) ) { // Get values from keys. $key_values = array_keys( $values ); From 5718fe35649114a1f1cbd45a64a2a891a12ac3cb Mon Sep 17 00:00:00 2001 From: pglewis Date: Fri, 8 Jun 2018 23:15:43 -0400 Subject: [PATCH 3/7] Include the issue history for this section --- classes/fields/pick.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/classes/fields/pick.php b/classes/fields/pick.php index a11d192e34..b4d9dcd571 100644 --- a/classes/fields/pick.php +++ b/classes/fields/pick.php @@ -1295,7 +1295,8 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ $edit_link = add_query_arg( array( 'pods_modal' => '1' ), $edit_link ); } - // Determine if this is a selected item + // Determine if this is a selected item. + // Issue history for setting selected: #4753, #4892, #5014 $selected = false; $values = array(); @@ -1313,7 +1314,7 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ // Cast key values in array as string. $key_values = array_map( 'strval', $key_values ); - + // Let's check to see if the current $item_id matches any key values. if ( in_array( (string) $item_id, $key_values, true ) ) { $selected = true; From 4d2cc4f2f19378f65ce24509634e50057a9ff0bb Mon Sep 17 00:00:00 2001 From: pglewis Date: Fri, 8 Jun 2018 23:17:33 -0400 Subject: [PATCH 4/7] Remove unintended extra space --- classes/fields/pick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/fields/pick.php b/classes/fields/pick.php index b4d9dcd571..b24e5d481d 100644 --- a/classes/fields/pick.php +++ b/classes/fields/pick.php @@ -1296,7 +1296,7 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ } // Determine if this is a selected item. - // Issue history for setting selected: #4753, #4892, #5014 + // Issue history for setting selected: #4753, #4892, #5014 $selected = false; $values = array(); From 9b7d3648d355e0e7238b5ec4595fd32bac6027a5 Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Wed, 14 Nov 2018 11:42:09 -0600 Subject: [PATCH 5/7] Update pick.php --- classes/fields/pick.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/fields/pick.php b/classes/fields/pick.php index b24e5d481d..6528681382 100644 --- a/classes/fields/pick.php +++ b/classes/fields/pick.php @@ -1305,6 +1305,9 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ if ( ! empty( $args->value ) ) { // The value may be a single non-array value. $values = (array) $args->value; + + // Cast values in array as string. + $values = array_map( 'strval', $values ); } // If the value array has keys as IDs, let's check for matches from the keys first. @@ -1323,9 +1326,6 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ // If we do not have a key match, the normal values may still match. if ( ! $selected ) { - // Cast values in array as string. - $values = array_map( 'strval', $values ); - // Let's check to see if the current $item_id matches any values. if ( in_array( (string) $item_id, $values, true ) ) { $selected = true; From 617ec51dde122f530b72a503cac6fa9a44af07ea Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Wed, 28 Nov 2018 10:15:19 -0600 Subject: [PATCH 6/7] Update pick.php --- classes/fields/pick.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/fields/pick.php b/classes/fields/pick.php index 6528681382..56c8ebfc7d 100644 --- a/classes/fields/pick.php +++ b/classes/fields/pick.php @@ -1305,11 +1305,11 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ if ( ! empty( $args->value ) ) { // The value may be a single non-array value. $values = (array) $args->value; - - // Cast values in array as string. - $values = array_map( 'strval', $values ); } + // Cast values in array as string. + $values = array_map( 'strval', $values ); + // If the value array has keys as IDs, let's check for matches from the keys first. if ( ! isset( $values[0] ) ) { // Get values from keys. From 15e518bd9b055f2375cdbc48c01a241a3ae42812 Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Mon, 2 Mar 2020 21:15:26 -0600 Subject: [PATCH 7/7] Update classes/fields/pick.php --- classes/fields/pick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/fields/pick.php b/classes/fields/pick.php index bfac24a815..cefc9b7dda 100644 --- a/classes/fields/pick.php +++ b/classes/fields/pick.php @@ -1305,7 +1305,7 @@ public function build_dfv_field_item_data_recurse_item( $item_id, $item_title, $ } // Determine if this is a selected item. - // Issue history for setting selected: #4753, #4892, #5014 + // Issue history for setting selected: #4753, #4892, #5014. $selected = false; $values = array();