Skip to content

Commit aff5c53

Browse files
committed
fix: multi-input field handling for zaak creation arguments
1 parent 790447a commit aff5c53

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

owc-gravityforms-zgw.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
* OWC GravityForms ZGW.
55
*
66
* @package OWC_GravityForms_ZGW
7-
*
87
* @author Yard | Digital Agency
9-
*
108
* @since 1.0.0
119
*
1210
* Plugin Name: OWC | GravityForms ZGW

src/Actions/CreateZaakAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
exit;
1717
}
1818

19-
use OWC\ZGW\Entities\Zaak;
2019
use OWCGravityFormsZGW\Contracts\AbstractCreateZaakAction;
20+
use OWC\ZGW\Entities\Zaak;
2121

2222
/**
2323
* Create Zaak action.

src/Contracts/AbstractCreateZaakAction.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use DateTime;
2020
use Exception;
21+
use GF_Field;
2122
use OWCGravityFormsZGW\ContainerResolver;
2223
use OWCGravityFormsZGW\GravityForms\FormUtils;
2324
use 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

Comments
 (0)