Issue #3414993 by alexpott: Add ConfigImporter to \Drupal\Core\Config\Importer\MissingContentEvent

merge-requests/6153/head^2
Dave Long 2024-02-18 13:46:18 +00:00
parent 5294815818
commit eafa856443
No known key found for this signature in database
GPG Key ID: ED52AE211E142771
3 changed files with 12 additions and 4 deletions

View File

@ -701,7 +701,7 @@ class ConfigImporter {
$missing_content = $sandbox['missing_content']['data']; $missing_content = $sandbox['missing_content']['data'];
} }
if (!empty($missing_content)) { 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. // Fire an event to allow listeners to create the missing content.
$this->eventDispatcher->dispatch($event, ConfigEvents::IMPORT_MISSING_CONTENT); $this->eventDispatcher->dispatch($event, ConfigEvents::IMPORT_MISSING_CONTENT);
$sandbox['missing_content']['data'] = $event->getMissingContent(); $sandbox['missing_content']['data'] = $event->getMissingContent();

View File

@ -2,14 +2,15 @@
namespace Drupal\Core\Config\Importer; 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. * Wraps a configuration event for event listeners.
* *
* @see \Drupal\Core\Config\ConfigEvents::IMPORT_MISSING_CONTENT * @see \Drupal\Core\Config\ConfigEvents::IMPORT_MISSING_CONTENT
*/ */
class MissingContentEvent extends Event { class MissingContentEvent extends ConfigImporterEvent {
/** /**
* A list of missing content dependencies. * A list of missing content dependencies.
@ -23,8 +24,11 @@ class MissingContentEvent extends Event {
* *
* @param array $missing_content * @param array $missing_content
* Missing content information. * 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; $this->missingContent = $missing_content;
} }

View File

@ -4,6 +4,7 @@ namespace Drupal\config_import_test;
use Drupal\Core\Config\ConfigCrudEvent; use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigEvents; use Drupal\Core\Config\ConfigEvents;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\ConfigImporterEvent; use Drupal\Core\Config\ConfigImporterEvent;
use Drupal\Core\Config\Importer\MissingContentEvent; use Drupal\Core\Config\Importer\MissingContentEvent;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
@ -72,6 +73,9 @@ class EventSubscriber implements EventSubscriberInterface {
* The missing content event. * The missing content event.
*/ */
public function onConfigImporterMissingContentTwo(MissingContentEvent $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) { 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(); $missing = $event->getMissingContent();
$uuid = key($missing); $uuid = key($missing);