List wrapping never wraps a single property map, making multi-value map inputs
## Problem/Motivation
`InputTypeCoercionSubscriber` wraps a value in a single-item array when a list or multiple definition receives something that is not a list, so that downstream code can iterate uniformly. The guard is:
```php
if ($is_list && !\is_array($value)) {
$event->setValue([$value]);
return;
}
```
A single property map — `{"target_id": 1}`, or any field item expressed as its property array — **is** a PHP array, so it is never wrapped. Typed data then receives an associative array where it expects a list of items and rejects it outright.
The failure is also harsher than a normal validation error. It surfaces as an `InputException` thrown from `TypedInputsTrait::doSetInputValue()` rather than as a violation on the result, so a caller gets an exception rather than a message it can act on:
```
The value input value is invalid: Invalid values given. Values must be represented as an associative array.
```
This makes any multi-value field effectively unsettable through `tool_belt:field_set_value` for the most natural single-item input shape. Callers must know to send `[{...}]` rather than `{...}`, which the advertised schema does not convey — and an LLM caller supplying one item has no reason to wrap it.
## Steps to reproduce
1. On an entity with a multi-value field (cardinality != 1), instantiate `tool_belt:field_set_value`.
2. Set `entity` and `field_name` so the input definition refines to a `MapInputDefinition` with `isMultiple() === TRUE`.
3. Set `value` to a single property map, e.g. `['target_id' => 1]`.
4. An `InputException` is thrown: _Values must be represented as an associative array._
5. Setting `value` to `[['target_id' => 1]]` instead does not hit this code path.
## Proposed resolution
Wrap when the value is not already a _list_, rather than when it is not an array:
```php
if ($is_list && (!\is_array($value) || !\array_is_list($value))) {
$event->setValue([$value]);
return;
}
```
Behaviour change is limited to two input shapes:
| Input | Before | After |
|-------|--------|-------|
| `'hello'`, `0`, `''` | wrapped | wrapped |
| `[]` | not wrapped | not wrapped |
| `['a', 'b']` | not wrapped | not wrapped |
| `[['target_id' => 1]]` | not wrapped | not wrapped |
| `['target_id' => 1]` | **not wrapped** | **wrapped** |
| `[1 => ['target_id' => 1]]` | **not wrapped** | **wrapped** |
The first changed row is the fix. The second is a deliberate consequence: an array with non-sequential integer keys (which is what a JSON object such as `{"1": {...}}` decodes to in PHP) is now wrapped and fails validation with a clear message, instead of being silently misread as a delta-keyed list. `array_is_list([])` returns `TRUE`, so an empty array is still treated as a valid empty list.
## Remaining tasks
Test coverage is included. `CoercionTestTool` gains a `variants` input — a `MapInputDefinition` with `multiple: TRUE` and `sku`/`quantity` properties — plus a matching output definition, and `InputTypeCoercionTest` gains three cases:
- `testSingleMapWrappedForMultipleMapInput()` — a single property map is wrapped, and its nested properties are still coerced through child dispatch (`'7'` → `7`), proving the wrap happens before the recursive subscriber.
- `testListOfMapsIsNotWrapped()` — an existing list of maps passes through unchanged.
- `testEmptyArrayIsNotWrappedForMultipleMapInput()` — an empty array stays an empty list.
All 24 tests in `InputTypeCoercionTest` pass with the change. Reverting the one-line condition and re-running makes `testSingleMapWrappedForMultipleMapInput()` error with the exact production symptom (`InvalidArgumentException: Invalid values given. Values must be represented as an associative array.` from `Map::setValue()` via `ItemList`), confirming the test exercises the reported defect rather than passing incidentally.
Note that this was verified through the synthetic test tool rather than against a real multi-value field. On the environment where the bug was found, every multi-value field is an entity reference and entity reference validation was independently broken (`SelectionPluginManager::getPluginId()` throwing `uasort(): Argument #1 ($array) must be of type array, null given`, reproducible with plain core `set()` + `validate()` and no tool involved), so an end-to-end write through `tool_belt:field_set_value` remains unconfirmed.
## Related
- `decodeJsonStructure()` has a matching gap: for a list target it requires `array_is_list($decoded)`, so a JSON string holding a single object (`'{"target_id":1}'`) is rejected and then wrapped as a raw string. Reconciling that with the wrapping above is a follow-up — the decode branch returns early and would bypass the wrapping fix, so the two paths need to be resolved together rather than by loosening the shape check alone.
### AI usage (if applicable)
- [x] **AI Assisted Issue:** This issue was generated with AI assistance, but was reviewed and refined by the creator.
- [ ] **AI Assisted Code:** This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.
- [x] **AI Generated Code:** This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.
- [ ] **Vibe Coded:** This code was generated by an AI and has only been functionally tested.
issue
GitLab AI Context
Project: project/tool
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/tool/-/raw/1.0.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/tool
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD