1818
1919use DateTime ;
2020use Exception ;
21+ use GF_Field ;
2122use OWCGravityFormsZGW \ContainerResolver ;
2223use OWCGravityFormsZGW \GravityForms \FormUtils ;
2324use OWCGravityFormsZGW \LoggerZGW ;
@@ -82,11 +83,11 @@ protected function get_mapped_required_zaak_creation_args(): array
8283 protected function map_required_zaak_creation_args (array $ args ): array
8384 {
8485 foreach ( $ this ->form ['fields ' ] as $ field ) {
85- if ( empty ( $ field ->mappedFieldValueZGW ) || ! isset ( $ args [ $ field ->mappedFieldValueZGW ] ) ) {
86+ if ( ! isset ( $ field ->mappedFieldValueZGW ) || ! is_string ( $ field -> mappedFieldValueZGW ) || '' === $ field -> mappedFieldValueZGW || ! isset ( $ args [ $ field ->mappedFieldValueZGW ] ) ) {
8687 continue ;
8788 }
8889
89- $ field_value = rgar ( $ this ->entry , ( string ) $ field-> id );
90+ $ field_value = $ this ->handle_zaak_creation_arg_value ( $ field );
9091
9192 if ( empty ( $ field_value ) ) {
9293 continue ;
@@ -102,6 +103,49 @@ protected function map_required_zaak_creation_args(array $args ): array
102103 return $ args ;
103104 }
104105
106+ /**
107+ * Handle getting the value for a "zaak" creation argument from multiple form fields and types.
108+ * Checkboxes for example can have multiple inputs.
109+ *
110+ * @since NEXT
111+ */
112+ protected function handle_zaak_creation_arg_value (GF_Field $ field ): string
113+ {
114+ if ( isset ( $ field ->inputs ) && is_array ( $ field ->inputs ) ) {
115+ $ field_value = '' ;
116+ $ input_values = array ();
117+
118+ foreach ( $ field ->inputs as $ input ) {
119+ $ input_id = (string ) ( $ input ['id ' ] ?? '' );
120+
121+ if ( '' === $ input_id ) {
122+ continue ;
123+ }
124+
125+ $ input_value = rgar ( $ this ->entry , $ input_id );
126+
127+ if ( ! is_string ( $ input_value ) || '' === $ input_value ) {
128+ continue ;
129+ }
130+
131+ $ input_values [] = trim ( $ input_value );
132+ }
133+
134+ $ count = count ( $ input_values );
135+
136+ $ field_value = match ( true ) {
137+ 0 === $ count => '' ,
138+ 1 === $ count => $ input_values [0 ],
139+ 2 === $ count => implode ( ' en ' , $ input_values ),
140+ 2 < $ count => implode ( ', ' , array_slice ( $ input_values , 0 , -1 ) ) . ' en ' . end ( $ input_values ),
141+ };
142+ } else {
143+ $ field_value = rgar ( $ this ->entry , (string ) $ field ->id );
144+ }
145+
146+ return is_string ( $ field_value ) && '' !== $ field_value ? $ field_value : '' ;
147+ }
148+
105149 /**
106150 * Assign a submitter to the created "zaak".
107151 */
@@ -206,6 +250,7 @@ protected function map_zaak_properties_args(): array
206250 }
207251
208252 $ property_value = rgar ( $ this ->entry , (string ) $ field ->id );
253+ dd ( $ property_value , $ field );
209254
210255 if ( empty ( $ property_value ) ) {
211256 continue ;
0 commit comments