From 234e2f5129ef34c0a7127c861252b5a946a81ded Mon Sep 17 00:00:00 2001 From: Stefan Korn Date: Fri, 4 Oct 2024 11:38:41 +0200 Subject: [PATCH] #4306: properties of schema array/items do not respect property specs regarding element type --- .../json_form_widget.services.yml | 2 +- modules/json_form_widget/src/ArrayHelper.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/json_form_widget/json_form_widget.services.yml b/modules/json_form_widget/json_form_widget.services.yml index 6a1ff74315..c3fb6dcc90 100644 --- a/modules/json_form_widget/json_form_widget.services.yml +++ b/modules/json_form_widget/json_form_widget.services.yml @@ -16,7 +16,7 @@ services: class: \Drupal\json_form_widget\ObjectHelper json_form.array_helper: class: \Drupal\json_form_widget\ArrayHelper - arguments: ['@json_form.object_helper'] + arguments: ['@json_form.object_helper', '@json_form.string_helper'] json_form.widget_router: class: \Drupal\json_form_widget\WidgetRouter arguments: ['@uuid','@json_form.string_helper', '@dkan.metastore.service'] diff --git a/modules/json_form_widget/src/ArrayHelper.php b/modules/json_form_widget/src/ArrayHelper.php index 09b13e19fe..bee2dca709 100644 --- a/modules/json_form_widget/src/ArrayHelper.php +++ b/modules/json_form_widget/src/ArrayHelper.php @@ -22,6 +22,14 @@ class ArrayHelper implements ContainerInjectionInterface { */ protected ObjectHelper $objectHelper; + + /** + * String Helper. + * + * @var StringHelper + */ + protected StringHelper $stringHelper; + /** * Builder object. * @@ -36,15 +44,17 @@ class ArrayHelper implements ContainerInjectionInterface { */ public static function create(ContainerInterface $container) { return new static( - $container->get('json_form.object_helper') + $container->get('json_form.object_helper'), + $container->get('json_form.string_helper') ); } /** * Constructor. */ - public function __construct(ObjectHelper $object_helper) { + public function __construct(ObjectHelper $object_helper, StringHelper $string_helper) { $this->objectHelper = $object_helper; + $this->stringHelper = $string_helper; } /** @@ -264,7 +274,7 @@ protected function buildArrayElement(array $definition, $data, FormStateInterfac */ protected function buildSimpleArrayElement(array $definition, $data): array { return array_filter([ - '#type' => 'textfield', + '#type' => $this->stringHelper->getElementType($definition['schema']->items), '#title' => $definition['schema']->items->title ?? NULL, '#default_value' => $data, ]);