Undefined array key "source" ConfigEventsSubscriber.php

Created on 6 September 2023, over 1 year ago
Updated 1 December 2023, about 1 year ago

Problem/Motivation

We have media types configuration translated and we install the website from configuration.
During the installation I got this warning, it happens, because translations don't have any 'source' key.

Steps to reproduce

Add config translation for your media types. Install clean website with this configuration

Solution

Check that we don't handle translations or just check that config has source key

πŸ› Bug report
Status

Closed: works as designed

Version

2.1

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium lobsterr

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

Comments & Activities

  • Issue created by @lobsterr
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.5 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    60 pass
  • @lobsterr opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium lobsterr

    I have tried to find a way to detect, if config is actually translation, but there is no methods for it.
    The only way we can check it by storage collection. Or maybe there is another way to do it.
    Anyway, I think in this case we just simply can check source and it would be enough

  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    @LOBsTerr - I'm having trouble reproducing this issue.

    Set up steps:

    1. Install a vanilla Drupal 10.1.x site
    2. Install oEmbed Providers module
    3. Install Configuration Translation
    4. Install Dutch language
    5. Create a 'Test Media Type' media type
    6. Add translation for media type configuration
    7. Export entire site config to ../config/sync

    If I drop the DB and re-install from existing config, I'm not seeing the warning.

    I also tried setting a breakpoint in ConfigEventsSubscriber::configSave(). If I alter the translated ../config/sync/language/nl/media.type.test_media_type.yml file and import, the breakpoint doesn't hit. If alter ../config/sync/media.type.test_media_type.yml file and import, the breakpoint does hit.

    So far as I can tell, ConfigEventsSubscriber::configSave() doesn't fire went translated config is imported.

  • πŸ‡§πŸ‡ͺBelgium lobsterr

    I will double check it on clean installation and will come to you

  • πŸ‡§πŸ‡ͺBelgium lobsterr

    I have followed almost exactly your steps, the only difference, I translated Image media type, instead of creating a custom one:
    and this what I see during the installation

    root@f91e89afa23e:/home/lob/www/clean-drupal# ./vendor/bin/drush 'site:install' minimal --root=/home/lob/www/clean-drupal/web/ --site-name='Clean Drupal website' --site-mail=info@example.org --locale=en --account-mail=admin@example.org --account-name=admin --account-pass=admin --sites-subdir=default --existing-config -y
     You are about to:
     * DROP all tables in your 'drupal' database.
    
     // Do you want to continue?: yes.                                                                                      
    
     [notice] Starting Drupal installation. This takes a while.
     [notice] Performed install task: install_select_language
     [notice] Performed install task: install_select_profile
     [notice] Performed install task: install_load_profile
     [notice] Performed install task: install_verify_requirements
     [notice] Performed install task: install_verify_database_ready
     [notice] Performed install task: install_base_system
     [notice] Performed install task: install_bootstrap_full
     [warning] Undefined array key "source" ConfigEventsSubscriber.php:68
     [warning] Undefined array key "source" ConfigEventsSubscriber.php:68
     [warning] Undefined array key "source" ConfigEventsSubscriber.php:68
    

    If you want I can share my configuration. I also set breakpoints to discover it in the first place and I just did it again. The same result as reported, Are you sure your debugger setup to work with CLI ?

  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    I'm able to reproduce the behavior when installing the site with Drush; however, it doesn't happen when the site is installed via UI. When installing with Drush, the breakpoint does hit, and I do see that 'source' is missing.

    Additional info:
    When running drush config:import to import either the media type or its translated config, ConfigEventsSubscriber::configSave() does not fire.

    Diving deeper:

    When installing via UI:
    In ConfigImporter::ImportConfig(), the following line returns an overrider:
    $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection);
    The config object loaded is Drupal\language\Config\LanguageCongigOverride, which has its own ->save() method, which dispatches a LanguageConfigOverrideCrudEvent event. The oEmbed Providers' ConfigEventsSubscriber subscriber is not triggered.

    When installing via Drush:
    In ConfigImporter::ImportConfig(), the following line does NOT return an overrider:
    $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection);
    The config object loaded is Drupal\Core\Config\Config. When its ->save() is called, it dispatches a ConfigCrudEvent event, which triggers the oEmbed Providers' ConfigEventsSubscriber subscriber.

  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    In ConfigImporter::ImportConfig(), when installing via UI, $this->configManager->getConfigCollectionInfo() returns two collections: language.en and langauge.nl. When installing via Drush, it returns only language.en.

    I spent some time digging into this, and it really gets into the weeds of the Drupal installer and how Drush invokes it. This is being caused by either a bug in core or in Drush.

  • Status changed to Closed: works as designed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    This module extends the provider-side of core's oEmbed functionality. If an issue does exist, it's a core issue. Please feel free to open an issue against Drupal core.

Production build 0.71.5 2024