Skip to content

admin_toolbar_tools + project_browser = TypeError during site installation due to string array keys #46

@jjroelofs

Description

@jjroelofs

Bug Description

The admin_toolbar_tools module causes a fatal TypeError during Drupal site installation when the project_browser module is enabled and configured via recipes.

Error Message

[warning] Array to string conversion ExtraLinks.php:745
[error] TypeError: Unsupported operand types: int + string in Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks->getDerivativeDefinitions() (line 749 of /var/www/html/web/modules/contrib/admin_toolbar/admin_toolbar_tools/src/Plugin/Derivative/ExtraLinks.php)

Root Cause Analysis

The issue occurs in ExtraLinks.php at line 749 with this code:

'weight' => -10 + $key,

Problem: During site installation via recipes, the project_browser.admin_settings config contains an enabled_sources array where the keys are strings ("0", "1") rather than integers (0, 1). When the code iterates over this array:

foreach ($project_browser_enabled_sources as $key => $source_id) {

The $key variable contains string values, causing PHP to throw a TypeError when trying to perform arithmetic: int + string.

Why it works after installation: After site installation, Drupal's config system normalizes array keys to proper integers, so the arithmetic operation works correctly.

Reproduction Steps

  1. Set up a Drupal installation with recipes that include project_browser module
  2. Configure project_browser.admin_settings with enabled_sources in recipe YAML
  3. Run drush site:install
  4. The error occurs during the menu rebuild process triggered by entity insertion hooks

Configuration Context

Recipe configuration that triggers the issue:

project_browser.admin_settings:
  simpleConfigUpdate:
    enabled_sources:
      - drupalorg_jsonapi
      - recipes

Proposed Solution

Cast the $key to integer before arithmetic operation:

'weight' => -10 + (int)$key,

Or use array_values() to ensure numeric keys:

foreach (array_values($project_browser_enabled_sources) as $key => $source_id) {

Environment

  • Drupal Core: 11.x
  • admin_toolbar version: Latest
  • Installation method: Drupal Recipes via drush site:install
  • Context: Site installation process

Impact

  • Blocks site installation when admin_toolbar_tools and project_browser are both enabled
  • Only affects installation process, not post-installation usage
  • Workaround: Remove project_browser module or disable admin_toolbar_tools during installation

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions