From b0927018d2700b6b2bf6162d15ec6f4969c3efa4 Mon Sep 17 00:00:00 2001 From: Matth_eu Date: Wed, 4 Dec 2013 23:30:27 +0000 Subject: [PATCH 1/2] don't store non-rep grouped field data as an array --- classes.fields.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classes.fields.php b/classes.fields.php index 2cf43bfd..0b05f2c1 100644 --- a/classes.fields.php +++ b/classes.fields.php @@ -1405,6 +1405,10 @@ public function parse_save_values() { $field_value = $field->get_values(); + // if the field is a repeatable field, store the whole array of them, if it's not repeatble, + // just store the first (and only) one directly + if ( ! $field->args['repeatable'] ) + $field_value = reset( $field_value ); } } From e82c2a0ed9e4acda9a5932d6e1f6c68c6da35d65 Mon Sep 17 00:00:00 2001 From: Matth_eu Date: Thu, 5 Dec 2013 10:05:13 +0000 Subject: [PATCH 2/2] update unit tests --- tests/testGroupField.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/testGroupField.php b/tests/testGroupField.php index e638729a..3287be02 100644 --- a/tests/testGroupField.php +++ b/tests/testGroupField.php @@ -5,8 +5,8 @@ class GroupFieldTestCase extends WP_UnitTestCase { function testAddField() { $group = new CMB_Group_Field( 'group', 'Group Title', array() ); - $field1 = new CMB_Text_Field( 'foo', 'Title', array( 1, 2 ) ); - $field2 = new CMB_Text_Field( 'bar', 'Title', array( 3, 4 ) ); + $field1 = new CMB_Text_Field( 'foo', 'Title', array( 1 ) ); + $field2 = new CMB_Text_Field( 'bar', 'Title', array( 2, 3 ), array( 'repeatable' => true ) ); $group->add_field( $field1 ); $group->add_field( $field2 ); @@ -39,22 +39,29 @@ function testGetValues() { function testParseSaveValues() { $group = new CMB_Group_Field( 'group', 'Group Title', array() ); - $field1 = new CMB_Text_Field( 'foo', 'Title', array( 1, 2 ) ); - $field2 = new CMB_Text_Field( 'bar', 'Title', array( 3, 4 ) ); + $field1 = new CMB_Text_Field( 'foo', 'Title', array( 1 ) ); + $field2 = new CMB_Text_Field( 'bar', 'Title', array( 2, 3 ), array( 'repeatable' => true ) ); $group->add_field( $field1 ); $group->add_field( $field2 ); - $group->set_values( $values = array( + $group->set_values( array( 'group' => array( - 'foo' => array( 1, 2 ) , - 'bar' => array( 1, 2 ) + 'foo' => array( 1 ), + 'bar' => array( 2, 3 ) ), ) ); + $expected = array( + 'group' => array( + 'foo' => 1, + 'bar' => array( 2, 3 ) + ) + ); + $group->parse_save_values(); - $this->assertEquals( $group->get_values(), $values ); + $this->assertEquals( $group->get_values(), $expected ); }