Reopening: the fix mentioned in #3612158: BadRequestException: entity_browser_select expects array, got string — incompatible with Symfony 7 (3.0.0) #3 does not seem to have been committed. The code of 3.0.4 is identical to 3.0.0 on this point, and the exception is still thrown:
$selection = $request->request->all('entity_browser_select');
if (empty($selection)) {
$selection = $request->request->get('entity_browser_select');
}Steps to reproduce (3.0.4, Drupal 11.4, Symfony 7)
- Use an entity browser with a View widget whose "Entity browser selection" field has "Use field cardinality" enabled: in the CKEditor 5 link UI, the cardinality is 1, so the selection is rendered as radio buttons.
- Open the entity browser from the CKEditor 5 link balloon, select an item and submit.
- The AJAX request fails with a 500 error: BadRequestException: Unexpected value for parameter "entity_browser_select": expecting "array", got "string".
The README recommends enabling "Use field cardinality", so this happens with the recommended configuration.
Cause
entity_browser_select is an array with checkboxes, and a string with radios. In Symfony 7, InputBag::all($key) throws when the value is not an array, and InputBag::get($key) throws when it is not a scalar ("Input value contains a non-scalar value"). So:
- the current code throws on radios, before reaching the get() fallback;
- the fix proposed in the summary (get() instead of all()) would throw on checkboxes.
Proposed fix
Read the raw parameter, which can be either type, and keep the existing normalization:
$selection = $request->request->all()['entity_browser_select'] ?? [];
$selection = is_array($selection) ? array_filter($selection) : array_filter([$selection]);Patch attached. Tested with radios (single selection) and checkboxes (multiple selection).
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | ckeditor5_entity_browser-3633056-radio-selection.patch | 1.09 KB | goz |
Issue fork ckeditor5_entity_browser-3633056
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
goz commented