bootstrap_container_definition should be merged with defaults

Created on 27 September 2024, 3 months ago

Problem/Motivation

I tried to set a container parameter in like this $settings['bootstrap_container_definition']['parameters']['foo'] = 'bar'; in a settings.php, but when I cleared cache I got and error that You have requested a non-existent service "cache.container"..

I dig deeper and I realized that I should have provided a complete bootstrap_container_definition definition with all necessary services (that may change in time).

Steps to reproduce

Proposed resolution

Merge incoming bootstrap_container_definition from Settings with default bootstrap container definitions.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

bootstrap system

Created by

πŸ‡­πŸ‡ΊHungary mxr576 Hungary

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mxr576
  • Pipeline finished with Canceled
    3 months ago
    Total: 162s
    #294445
  • πŸ‡­πŸ‡ΊHungary mxr576 Hungary

    Let's see if this idea and solution stands before test writing.

  • Pipeline finished with Failed
    3 months ago
    Total: 176s
    #294466
  • Pipeline finished with Success
    3 months ago
    Total: 806s
    #294471
  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Is there ever a reason to unset any key from the container definition? If so then that is not possible with merging.

  • πŸ‡­πŸ‡ΊHungary mxr576 Hungary

    I do not think there is a use case for unsetting, only overriding.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Let's say we want to swap out cache.container for a different backend. We probably want to replace the arguments array - but NestedArray::mergeDeep() will append new arguments instead of replacing:

    $bootstrap['services']['cache.container'] = [
      'class' => 'Drupal\Core\Cache\DatabaseBackend',
      'arguments' => ['@database', '@cache_tags_provider.container', 'container', Drupal\Core\Cache\DatabaseBackend::MAXIMUM_NONE],
    ];
    
    $bootstrap2['services']['cache.container'] = [
      'class' => 'Other\Service',
      'arguments' => ['@other_backend'],
    ];
    
    > Drupal\Component\Utility\NestedArray::mergeDeep($bootstrap, $bootstrap2);
    = [
        "services" => [
          "cache.container" => [
            "class" => "Other\Service",
            "arguments" => [
              "@database",
              "@cache_tags_provider.container",
              "container",
              -1,
              "@other_backend",
            ],
          ],
        ],
      ]
    
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Believe NW is the current status but let me know if I'm wrong.

Production build 0.71.5 2024