From 15a2ed0c6d0b4e5f7c94f92c72f99fc6f0d878b0 Mon Sep 17 00:00:00 2001 From: Janette Day Date: Wed, 28 Dec 2022 11:37:38 -0600 Subject: [PATCH] Add checks to json_form_widget (#3891) --- modules/json_form_widget/src/ValueHandler.php | 7 ++++--- modules/json_form_widget/src/WidgetRouter.php | 2 ++ .../tests/src/Unit/SchemaUiHandlerTest.php | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/json_form_widget/src/ValueHandler.php b/modules/json_form_widget/src/ValueHandler.php index 394d0708f5..35f351f386 100644 --- a/modules/json_form_widget/src/ValueHandler.php +++ b/modules/json_form_widget/src/ValueHandler.php @@ -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; } diff --git a/modules/json_form_widget/src/WidgetRouter.php b/modules/json_form_widget/src/WidgetRouter.php index cba3047cea..b727963019 100644 --- a/modules/json_form_widget/src/WidgetRouter.php +++ b/modules/json_form_widget/src/WidgetRouter.php @@ -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; diff --git a/modules/json_form_widget/tests/src/Unit/SchemaUiHandlerTest.php b/modules/json_form_widget/tests/src/Unit/SchemaUiHandlerTest.php index d72d0c181b..a006169138 100644 --- a/modules/json_form_widget/tests/src/Unit/SchemaUiHandlerTest.php +++ b/modules/json_form_widget/tests/src/Unit/SchemaUiHandlerTest.php @@ -560,6 +560,7 @@ public function testSchemaUi() { 'arcgis' => 'arcgis', 'csv' => 'csv', ], + '#other_option' => '', '#default_value' => 'csv', ], ]; @@ -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); @@ -675,6 +677,7 @@ public function testAutocompleteOnComplex() { 'Option 1' => 'Option 1', 'Option 2' => 'Option 2', ], + '#other_option' => '', '#multiple' => TRUE, '#autocreate' => TRUE, '#target_type' => 'node', @@ -737,6 +740,7 @@ public function testAutocompleteOnSimple() { 'Option 1' => 'Option 1', 'Option 2' => 'Option 2', ], + '#other_option' => '', '#multiple' => TRUE, '#autocreate' => TRUE, '#target_type' => 'node', @@ -828,6 +832,7 @@ public function testAutocompleteHideActions() { 'Option 1' => 'Option 1', 'Option 2' => 'Option 2', ], + '#other_option' => '', '#multiple' => TRUE, '#autocreate' => TRUE, '#target_type' => 'node', @@ -881,6 +886,7 @@ public function testAutocompleteHideActions() { 'Option 1' => 'Option 1', 'Option 2' => 'Option 2', ], + '#other_option' => '', '#multiple' => TRUE, '#autocreate' => TRUE, '#target_type' => 'node',