Skip to content

Commit

Permalink
GetDKAN#4306: properties of schema array/items do not respect propert…
Browse files Browse the repository at this point in the history
…y specs regarding element type
  • Loading branch information
stefan-korn committed Oct 4, 2024
1 parent 6c76da2 commit 234e2f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/json_form_widget/json_form_widget.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
16 changes: 13 additions & 3 deletions modules/json_form_widget/src/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class ArrayHelper implements ContainerInjectionInterface {
*/
protected ObjectHelper $objectHelper;


/**
* String Helper.
*
* @var StringHelper
*/
protected StringHelper $stringHelper;

/**
* Builder object.
*
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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,
]);
Expand Down

0 comments on commit 234e2f5

Please sign in to comment.