From 0f400a3043b0f33a42b165d6fc45b827e1a49aa0 Mon Sep 17 00:00:00 2001 From: Dan Westall Date: Fri, 17 Mar 2017 12:42:28 +0000 Subject: [PATCH 1/5] Fix #422 for gmap grouped field data structure --- fields/class-cmb-field.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fields/class-cmb-field.php b/fields/class-cmb-field.php index b5d0b473..07cd693a 100644 --- a/fields/class-cmb-field.php +++ b/fields/class-cmb-field.php @@ -496,8 +496,15 @@ public function display() { $this->description(); $i = 0; + + // If the map field is not repeatable then we need to wrap it within an array to remove different in data structure between a repeater field and none if ( isset( $this->args['type'] ) && 'gmap' == $this->args['type'] ) { - $values = array( $values ); + if ( $this->args['repeatable'] === false && ! isset( $this->parent ) ) { + $values = array( $values ); + } + if( $this->args['repeatable'] === false && isset( $this->parent ) ) { + $values = $values[0]; + } } foreach ( $values as $key => $value ) { From 4608b404c18e87150d40242a271017b77a66110f Mon Sep 17 00:00:00 2001 From: Dan Westall Date: Fri, 17 Mar 2017 12:43:22 +0000 Subject: [PATCH 2/5] Fix code style --- fields/class-cmb-field.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fields/class-cmb-field.php b/fields/class-cmb-field.php index 07cd693a..a9e6c33d 100644 --- a/fields/class-cmb-field.php +++ b/fields/class-cmb-field.php @@ -499,10 +499,10 @@ public function display() { // If the map field is not repeatable then we need to wrap it within an array to remove different in data structure between a repeater field and none if ( isset( $this->args['type'] ) && 'gmap' == $this->args['type'] ) { - if ( $this->args['repeatable'] === false && ! isset( $this->parent ) ) { + if ( $this->args['repeatable'] === false && ! isset( $this->parent ) ) { $values = array( $values ); } - if( $this->args['repeatable'] === false && isset( $this->parent ) ) { + if ( $this->args['repeatable'] === false && isset( $this->parent ) ) { $values = $values[0]; } } From c5307d680fc5e9e5cabefe2a4dd439ecca36bee4 Mon Sep 17 00:00:00 2001 From: Dan Westall Date: Fri, 17 Mar 2017 15:28:54 +0000 Subject: [PATCH 3/5] Add check for data formats --- fields/class-cmb-field.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fields/class-cmb-field.php b/fields/class-cmb-field.php index a9e6c33d..ac87e3e8 100644 --- a/fields/class-cmb-field.php +++ b/fields/class-cmb-field.php @@ -502,8 +502,12 @@ public function display() { if ( $this->args['repeatable'] === false && ! isset( $this->parent ) ) { $values = array( $values ); } - if ( $this->args['repeatable'] === false && isset( $this->parent ) ) { + + // If its within a group then we need to unwrap it from the group, + // transitions code for data formats see https://github.com/humanmade/Custom-Meta-Boxes/issues/422 + if ( $this->args['repeatable'] === false && isset( $this->parent ) && count( $values ) === 1 ) { $values = $values[0]; + } } From dabe52e5c6c0266e0bab683899d259f47d1a89ab Mon Sep 17 00:00:00 2001 From: Dan Westall Date: Fri, 17 Mar 2017 15:39:28 +0000 Subject: [PATCH 4/5] Add fix for historical data structure transition --- fields/class-cmb-field.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fields/class-cmb-field.php b/fields/class-cmb-field.php index ac87e3e8..503caf58 100644 --- a/fields/class-cmb-field.php +++ b/fields/class-cmb-field.php @@ -504,10 +504,13 @@ public function display() { } // If its within a group then we need to unwrap it from the group, - // transitions code for data formats see https://github.com/humanmade/Custom-Meta-Boxes/issues/422 - if ( $this->args['repeatable'] === false && isset( $this->parent ) && count( $values ) === 1 ) { + if ( $this->args['repeatable'] === false && isset( $this->parent ) ) { $values = $values[0]; + // Transitions code for data formats see https://github.com/humanmade/Custom-Meta-Boxes/issues/422 + if ( count( $values ) !== 1 ) { + $values = array( $values ); + } } } From f564d3801e8441f9b3097945e51531c76474ffb3 Mon Sep 17 00:00:00 2001 From: mikeselander Date: Sun, 19 Mar 2017 20:34:52 -0700 Subject: [PATCH 5/5] Fixed comments --- fields/class-cmb-field.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fields/class-cmb-field.php b/fields/class-cmb-field.php index 503caf58..7a62003e 100644 --- a/fields/class-cmb-field.php +++ b/fields/class-cmb-field.php @@ -497,8 +497,9 @@ public function display() { $i = 0; - // If the map field is not repeatable then we need to wrap it within an array to remove different in data structure between a repeater field and none - if ( isset( $this->args['type'] ) && 'gmap' == $this->args['type'] ) { + // If the map field is not repeatable then we need to wrap it within an + // array to remove difference in data structure between a repeater field and normal + if ( isset( $this->args['type'] ) && 'gmap' === $this->args['type'] ) { if ( $this->args['repeatable'] === false && ! isset( $this->parent ) ) { $values = array( $values ); } @@ -507,7 +508,8 @@ public function display() { if ( $this->args['repeatable'] === false && isset( $this->parent ) ) { $values = $values[0]; - // Transitions code for data formats see https://github.com/humanmade/Custom-Meta-Boxes/issues/422 + // Transitions code for data formats see: + // https://github.com/humanmade/Custom-Meta-Boxes/issues/422 if ( count( $values ) !== 1 ) { $values = array( $values ); }