Skip to content

Commit

Permalink
Add checks to json_form_widget (#3891)
Browse files Browse the repository at this point in the history
  • Loading branch information
janette authored Dec 28, 2022
1 parent 6cd2c18 commit 15a2ed0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/json_form_widget/src/ValueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ public function handleArrayValues($formValues, $property, $schema) {
if ($subschema->type === "object") {
return $this->getObjectInArrayData($formValues, $property, $subschema);
}

foreach ($formValues[$property][$property] as $value) {
$data = array_merge($data, $this->flattenArraysInArrays($value));
if (isset($formValues[$property][$property])) {
foreach ($formValues[$property][$property] as $value) {
$data = array_merge($data, $this->flattenArraysInArrays($value));
}
}
return !empty($data) ? $data : FALSE;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/json_form_widget/src/WidgetRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public function getDropdownElement($element, $spec, $titleProperty = FALSE) {
$element = $this->handleSelectOtherDefaultValue($element, $element['#options']);
$element['#input_type'] = isset($spec->other_type) ? $spec->other_type : 'textfield';
}
$element['#other_option'] = isset($element['#other_option']) ?? FALSE;

if ($element['#type'] === 'select2') {
$element['#multiple'] = isset($spec->multiple) ? TRUE : FALSE;
$element['#autocreate'] = isset($spec->allowCreate) ? TRUE : FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ public function testSchemaUi() {
'arcgis' => 'arcgis',
'csv' => 'csv',
],
'#other_option' => '',
'#default_value' => 'csv',
],
];
Expand Down Expand Up @@ -604,6 +605,7 @@ public function testSchemaUi() {
],
'#default_value' => 'https://url.to.api.or.file',
'#input_type' => 'textfield',
'#other_option' => '',
],
];
$form = $ui_handler->applySchemaUi($form);
Expand Down Expand Up @@ -675,6 +677,7 @@ public function testAutocompleteOnComplex() {
'Option 1' => 'Option 1',
'Option 2' => 'Option 2',
],
'#other_option' => '',
'#multiple' => TRUE,
'#autocreate' => TRUE,
'#target_type' => 'node',
Expand Down Expand Up @@ -737,6 +740,7 @@ public function testAutocompleteOnSimple() {
'Option 1' => 'Option 1',
'Option 2' => 'Option 2',
],
'#other_option' => '',
'#multiple' => TRUE,
'#autocreate' => TRUE,
'#target_type' => 'node',
Expand Down Expand Up @@ -828,6 +832,7 @@ public function testAutocompleteHideActions() {
'Option 1' => 'Option 1',
'Option 2' => 'Option 2',
],
'#other_option' => '',
'#multiple' => TRUE,
'#autocreate' => TRUE,
'#target_type' => 'node',
Expand Down Expand Up @@ -881,6 +886,7 @@ public function testAutocompleteHideActions() {
'Option 1' => 'Option 1',
'Option 2' => 'Option 2',
],
'#other_option' => '',
'#multiple' => TRUE,
'#autocreate' => TRUE,
'#target_type' => 'node',
Expand Down

0 comments on commit 15a2ed0

Please sign in to comment.