From eafa856443000bf8022165f588753a57639daa1a Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Sun, 18 Feb 2024 13:46:18 +0000
Subject: [PATCH] Issue #3414993 by alexpott: Add ConfigImporter to
 \Drupal\Core\Config\Importer\MissingContentEvent

---
 core/lib/Drupal/Core/Config/ConfigImporter.php         |  2 +-
 .../Core/Config/Importer/MissingContentEvent.php       | 10 +++++++---
 .../tests/config_import_test/src/EventSubscriber.php   |  4 ++++
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php
index 8331c1bc7c04..20c9fcadfcd3 100644
--- a/core/lib/Drupal/Core/Config/ConfigImporter.php
+++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
@@ -701,7 +701,7 @@ protected function processMissingContent(&$context) {
       $missing_content = $sandbox['missing_content']['data'];
     }
     if (!empty($missing_content)) {
-      $event = new MissingContentEvent($missing_content);
+      $event = new MissingContentEvent($missing_content, $this);
       // Fire an event to allow listeners to create the missing content.
       $this->eventDispatcher->dispatch($event, ConfigEvents::IMPORT_MISSING_CONTENT);
       $sandbox['missing_content']['data'] = $event->getMissingContent();
diff --git a/core/lib/Drupal/Core/Config/Importer/MissingContentEvent.php b/core/lib/Drupal/Core/Config/Importer/MissingContentEvent.php
index 4b3dce9fc40f..e76cc1140232 100644
--- a/core/lib/Drupal/Core/Config/Importer/MissingContentEvent.php
+++ b/core/lib/Drupal/Core/Config/Importer/MissingContentEvent.php
@@ -2,14 +2,15 @@
 
 namespace Drupal\Core\Config\Importer;
 
-use Drupal\Component\EventDispatcher\Event;
+use Drupal\Core\Config\ConfigImporter;
+use Drupal\Core\Config\ConfigImporterEvent;
 
 /**
  * Wraps a configuration event for event listeners.
  *
  * @see \Drupal\Core\Config\ConfigEvents::IMPORT_MISSING_CONTENT
  */
-class MissingContentEvent extends Event {
+class MissingContentEvent extends ConfigImporterEvent {
 
   /**
    * A list of missing content dependencies.
@@ -23,8 +24,11 @@ class MissingContentEvent extends Event {
    *
    * @param array $missing_content
    *   Missing content information.
+   * @param \Drupal\Core\Config\ConfigImporter $config_importer
+   *   The config importer that triggered this event.
    */
-  public function __construct(array $missing_content) {
+  public function __construct(array $missing_content, ConfigImporter $config_importer) {
+    parent::__construct($config_importer);
     $this->missingContent = $missing_content;
   }
 
diff --git a/core/modules/config/tests/config_import_test/src/EventSubscriber.php b/core/modules/config/tests/config_import_test/src/EventSubscriber.php
index 4da76d83df69..60fd4501436f 100644
--- a/core/modules/config/tests/config_import_test/src/EventSubscriber.php
+++ b/core/modules/config/tests/config_import_test/src/EventSubscriber.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Config\ConfigCrudEvent;
 use Drupal\Core\Config\ConfigEvents;
+use Drupal\Core\Config\ConfigImporter;
 use Drupal\Core\Config\ConfigImporterEvent;
 use Drupal\Core\Config\Importer\MissingContentEvent;
 use Drupal\Core\State\StateInterface;
@@ -72,6 +73,9 @@ public function onConfigImporterMissingContentOne(MissingContentEvent $event) {
    *   The missing content event.
    */
   public function onConfigImporterMissingContentTwo(MissingContentEvent $event) {
+    if (!$event->getConfigImporter() instanceof ConfigImporter) {
+      throw new \LogicException('\Drupal\Core\Config\Importer\MissingContentEvent is missing the ConfigImporter');
+    }
     if ($this->state->get('config_import_test.config_import_missing_content', FALSE) && $this->state->get('config_import_test.config_import_missing_content_two', FALSE) === FALSE) {
       $missing = $event->getMissingContent();
       $uuid = key($missing);
-- 
GitLab