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 41

I 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

  1. Install Drupal 11.4.x with JSON:API Extras enabled.
  2. 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.

CommentFileSizeAuthor
#3 array_to_string_conv-3608182-2.patch2.35 KBjrockowitz
Command icon 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

jrockowitz created an issue. See original summary.

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new2.35 KB

Added 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.)

bbrala made their first commit to this issue’s fork.

bbrala’s picture

Status: Needs review » Reviewed & tested by the community

Yeah makes sense, merging.

bbrala’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • bbrala committed 6dcfaf97 on 8.x-3.x authored by jrockowitz
    fix: #3608182 Array to string conversion warning during route rebuild on...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.