From 643f19ead7cb8e933e782ecd9901b76c610ea5f5 Mon Sep 17 00:00:00 2001 From: Scott Kingsley Clark Date: Sun, 3 Sep 2023 08:19:42 -0500 Subject: [PATCH] Handle arrays of values with PodsUI when calling ui field method --- classes/PodsUI.php | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/classes/PodsUI.php b/classes/PodsUI.php index c19b431de2..cd29cd6d40 100644 --- a/classes/PodsUI.php +++ b/classes/PodsUI.php @@ -3991,18 +3991,29 @@ public function table( $reorder = false ) { ); } } else { - ob_start(); + $row_value_is_array = is_array( $row_value ); + $row_values = (array) $row_value; - $field_value = PodsForm::field_method( $attributes['type'], 'ui', $this->id, $row_value, $field, $attributes, $fields, $this->pod ); + foreach ( $row_values as $row_value_key => $row_value_item ) { + ob_start(); - $field_output = trim( (string) ob_get_clean() ); + $field_value = PodsForm::field_method( $attributes['type'], 'ui', $this->id, $row_value_item, $field, $attributes, $fields, $this->pod ); - if ( false === $field_value ) { - $row_value = ''; - } elseif ( 0 < strlen( trim( (string) $field_value ) ) ) { - $row_value = trim( (string) $field_value ); - } elseif ( 0 < strlen( $field_output ) ) { - $row_value = $field_output; + $field_output = trim( (string) ob_get_clean() ); + + if ( false === $field_value ) { + $row_values[ $row_value_key ] = ''; + } elseif ( $field_value && 0 < strlen( trim( (string) $field_value ) ) ) { + $row_values[ $row_value_key ] = trim( (string) $field_value ); + } elseif ( $field_output && 0 < strlen( $field_output ) ) { + $row_values[ $row_value_key ] = $field_output; + } + } + + $row_value = $row_values; + + if ( ! $row_value_is_array ) { + $row_value = $row_value ? current( $row_value ) : null; } }//end if