diff --git a/modules/json_form_widget/src/ArrayHelper.php b/modules/json_form_widget/src/ArrayHelper.php index 687d48dd62..da2e87bd3e 100644 --- a/modules/json_form_widget/src/ArrayHelper.php +++ b/modules/json_form_widget/src/ArrayHelper.php @@ -190,6 +190,18 @@ protected function buildSimpleArrayElement(array $definition, $data, array $cont ]; } + /** + * Flatten array element fieldset w/buttons for processing. + * + * @param array $element + * A form element. + */ + public static function flattenArrayElementFieldset(array &$element): void { + if (isset($element['field']) && $element['#type'] == 'fieldset') { + $element = ['#required' => ($element['#required'] ?? FALSE)] + $element['field']; + } + } + /** * Returns single complex element from array. * diff --git a/modules/json_form_widget/src/SchemaUiHandler.php b/modules/json_form_widget/src/SchemaUiHandler.php index 75a0320f45..57d20ca5e4 100644 --- a/modules/json_form_widget/src/SchemaUiHandler.php +++ b/modules/json_form_widget/src/SchemaUiHandler.php @@ -173,7 +173,7 @@ public function applyOnBaseField(mixed $spec, array $element) { $element = $this->changeFieldDescriptions($spec->{"ui:options"}, $element); $element = $this->changeFieldTitle($spec->{"ui:options"}, $element); if (isset($spec->{"ui:options"}->hideActions)) { - $element = $this->flattenArrays($spec->{"ui:options"}, $element); + // $element = $this->flattenArrays($spec->{"ui:options"}, $element); } } return $element; @@ -194,6 +194,7 @@ public function flattenArrays(mixed $spec, array $element) { unset($element['actions']); $default_value = []; foreach ($element[$spec->child] as $key => $item) { + ArrayHelper::flattenArrayElementFieldset($item); $default_value = array_merge($default_value, $this->formatArrayDefaultValue($item)); if ($key != 0) { unset($element[$spec->child][$key]); diff --git a/modules/json_form_widget/src/WidgetRouter.php b/modules/json_form_widget/src/WidgetRouter.php index 5081b32d81..00a0663558 100644 --- a/modules/json_form_widget/src/WidgetRouter.php +++ b/modules/json_form_widget/src/WidgetRouter.php @@ -147,11 +147,7 @@ public function handleListElement(mixed $spec, array $element) { * The dropdown element configured. */ public function getDropdownElement(mixed $element, mixed $spec, mixed $titleProperty = FALSE) { - // Array elements may be fieldsets, since by default they are simple array - // elements with Remove/Up/Down buttons. - if (isset($element['field']) && $element['#type'] == 'fieldset') { - $element = ['#required' => ($element['#required'] ?? FALSE)] + $element['field']; - } + ArrayHelper::flattenArrayElementFieldset($element); $element['#type'] = $this->getSelectType($spec); $element['#options'] = $this->getDropdownOptions($spec->source, $titleProperty); if ($element['#type'] === 'select_or_other_select') {