Problem/Motivation
After updating to Drupal 11.4.x, enabling JSON:API Extras can trigger this warning during a route/cache rebuild:
Warning: Array to string conversion in /var/www/html/web/core/lib/Drupal/Core/Routing/AttributeRouteDiscovery.php on line 41I reproduced this while installing a recipe that enables JSON:API Extras and then confirmed it also happens on drush cr.
The root cause is the namespace registration in JsonapiExtrasServiceProvider::alter():
$container_namespaces['Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras'][] = $jsonapi_impostor_path;That creates an array-valued entry in container.namespaces:
Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras => [ 'modules/contrib/jsonapi_extras/src-impostor-normalizers', ]
This worked without a visible warning in Drupal 11.3. In a local Drupal 11.3.11 checkout, Drupal\Core\Routing\AttributeRouteDiscovery and the router.builder.attributes service are not present.
In Drupal 11.4.0, core adds Drupal\Core\Routing\AttributeRouteDiscovery and registers it as router.builder.attributes. Its collectRoutes() method iterates @container.namespaces and assumes every namespace value is a string path:
foreach ($this->namespaces as $namespace => $directory) { $directory .= '/Controller'; $namespace .= '\Controller';
Because JSON:API Extras registers this unique impostor namespace as an array, Drupal 11.4 attempts to concatenate an array with '/Controller', causing the warning.
Steps to reproduce
- Install Drupal 11.4.x with JSON:API Extras enabled.
- Run
drush cr.
Expected result: cache rebuild completes without warnings.
Actual result: PHP emits Array to string conversion from AttributeRouteDiscovery.php.
Proposed resolution
Register the unique impostor namespace as a string path instead of appending it as an array item:
-$container_namespaces['Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras'][] = $jsonapi_impostor_path; +$container_namespaces['Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_extras'] = $jsonapi_impostor_path;
This should work on both Drupal 11.3 and 11.4. Drupal's DrupalKernel::classLoaderAddMultiplePsr4() accepts either a string PSR-4 base directory or an array of base directories in both checked versions. Since this namespace key is unique to JSON:API Extras, a string is sufficient and avoids the Drupal 11.4 attribute route discovery warning.
Remaining tasks
- Add/keep kernel test coverage that the impostor normalizer namespace is registered as a string.
- Open a merge request with the one-line fix.
User interface changes
None.
API changes
None.
Data model changes
None.
AI disclosure
This issue summary and proposed code change were generated using Codex 5.5 and reviewed by jrockowitz.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | array_to_string_conv-3608182-2.patch | 2.35 KB | jrockowitz |
Issue fork jsonapi_extras-3608182
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 #3
jrockowitz commentedAdded a patch generated from MR !87 for Composer-based consumers that still need a patch URL.
Patch: https://www.drupal.org/files/issues/2026-07-03/array_to_string_conv-3608...
MR: https://git.drupalcode.org/project/jsonapi_extras/-/merge_requests/87
AI-Generated: Yes (Used Codex 5.5 to generate and attach the patch from MR !87, then wire it into local Composer patch configuration. Reviewed by jrockowitz.)
Comment #5
bbralaYeah makes sense, merging.
Comment #6
bbrala