diff --git a/core/core.services.yml b/core/core.services.yml index 749c58e..9df9059 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -123,7 +123,7 @@ services: - { name: service_collector, tag: 'config.factory.override', call: addOverride } arguments: ['@config.storage', '@event_dispatcher', '@config.typed'] config.importer_subscriber: - class: Drupal\Core\Config\Importer\EventSubscriber + class: Drupal\Core\Config\Importer\FinalMissingContentSubscriber tags: - { name: event_subscriber } config.installer: diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index 9698617..ca9ffaa 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -614,25 +614,32 @@ protected function processConfigurations(array &$context) { } } + /** + * Handles processing of missing content. + * + * @param array $context + * Standard batch context. + */ protected function processMissingContent(array &$context) { - if (!isset($context['sandbox']['config']['missing_content'])) { + $sandbox = &$context['sandbox']['config']; + if (!isset($sandbox['missing_content'])) { $missing_content = $this->configManager->findMissingContentDependencies(); - $context['sandbox']['config']['missing_content']['data'] = $missing_content; - $context['sandbox']['config']['missing_content']['total'] = count($missing_content); + $sandbox['missing_content']['data'] = $missing_content; + $sandbox['missing_content']['total'] = count($missing_content); } else { - $missing_content = $context['sandbox']['config']['missing_content']['data']; + $missing_content = $sandbox['missing_content']['data']; } if (!empty($missing_content)) { $event = new MissingContentEvent($missing_content); // Fire an event to allow listeners to create the missing content. $this->eventDispatcher->dispatch(ConfigEvents::IMPORT_MISSING_CONTENT, $event); - $context['sandbox']['config']['missing_content']['data'] = $event->getMissingContent(); + $sandbox['missing_content']['data'] = $event->getMissingContent(); } - $current_count = count($context['sandbox']['config']['missing_content']['data']); + $current_count = count($sandbox['missing_content']['data']); if ($current_count) { $context['message'] = $this->t('Resolving missing content'); - $context['finished'] = ($context['sandbox']['config']['missing_content']['total'] - $current_count) / $context['sandbox']['config']['missing_content']['total']; + $context['finished'] = ($sandbox['missing_content']['total'] - $current_count) / $sandbox['missing_content']['total']; } else { $context['finished'] = 1; diff --git a/core/lib/Drupal/Core/Config/Importer/EventSubscriber.php b/core/lib/Drupal/Core/Config/Importer/FinalMissingContentSubscriber.php similarity index 68% rename from core/lib/Drupal/Core/Config/Importer/EventSubscriber.php rename to core/lib/Drupal/Core/Config/Importer/FinalMissingContentSubscriber.php index 9cce5ce..592ab5f 100644 --- a/core/lib/Drupal/Core/Config/Importer/EventSubscriber.php +++ b/core/lib/Drupal/Core/Config/Importer/FinalMissingContentSubscriber.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Config\Importer\EventSubscriber. + * Contains \Drupal\Core\Config\Importer\FinalMissingContentSubscriber. */ namespace Drupal\Core\Config\Importer; @@ -18,8 +18,14 @@ * * @see \Drupal\Core\Config\ConfigImporter::processMissingContent() */ -class EventSubscriber implements EventSubscriberInterface { +class FinalMissingContentSubscriber implements EventSubscriberInterface { + /** + * Handles the missing content event. + * + * @param \Drupal\Core\Config\Importer\MissingContentEvent $event + * The missing content event. + */ public function onMissingContent(MissingContentEvent $event) { foreach (array_keys($event->getMissingContent()) as $uuid) { $event->resolveMissingContent($uuid); @@ -29,10 +35,10 @@ public function onMissingContent(MissingContentEvent $event) { /** * {@inheritdoc} */ - static function getSubscribedEvents() { + public static function getSubscribedEvents() { // This should always be the final event as it will mark all content // dependencies as resolved. - $events[ConfigEvents::IMPORT_MISSING_CONTENT][] = array('onMissingContent', 1024); + $events[ConfigEvents::IMPORT_MISSING_CONTENT][] = array('onMissingContent', -1024); return $events; } diff --git a/core/lib/Drupal/Core/Config/Importer/MissingContentEvent.php b/core/lib/Drupal/Core/Config/Importer/MissingContentEvent.php index 1bbe849..c77fb80 100644 --- a/core/lib/Drupal/Core/Config/Importer/MissingContentEvent.php +++ b/core/lib/Drupal/Core/Config/Importer/MissingContentEvent.php @@ -19,7 +19,7 @@ class MissingContentEvent extends Event { * * @var array */ - protected $config; + protected $missingContent; /** * Constructs a configuration import missing content event object. @@ -35,6 +35,7 @@ public function __construct(array $missing_content) { * Gets missing content information. * * @return array + * The missing content. */ public function getMissingContent() { return $this->missingContent; @@ -46,7 +47,7 @@ public function getMissingContent() { * Calling this also stops event propagation so that if the event subscriber * does actually creates content it will work nicely with the batch system. * - * @param $uuid + * @param string $uuid * The UUID of the content entity to mark resolved. * * @return $this @@ -55,13 +56,6 @@ public function getMissingContent() { public function resolveMissingContent($uuid) { if (isset($this->missingContent[$uuid])) { unset($this->missingContent[$uuid]); - // Stop propagation if the subscriber resolves any conflicts. This allows - // multiple events to listen to the missing content event and interact - // with the config importer in a batch. - // \Drupal\Core\Config\Importer\EventSubscriber implements an event to - // catch any unresolved content dependencies and mark them all as resolved - // so that config importing can complete. - $this->stopPropagation(); } else { // @todo throw an exception? Atm I don't think so. @@ -70,4 +64,3 @@ public function resolveMissingContent($uuid) { } } -