resolveMissingContent example

/** * Handles the missing content event. * * @param \Drupal\Core\Config\Importer\MissingContentEvent $event * The missing content event. */
  public function onConfigImporterMissingContentOne(MissingContentEvent $event) {
    if ($this->state->get('config_import_test.config_import_missing_content', FALSE) && $this->state->get('config_import_test.config_import_missing_content_one', FALSE) === FALSE) {
      $missing = $event->getMissingContent();
      $uuid = key($missing);
      $this->state->set('config_import_test.config_import_missing_content_one', key($missing));
      $event->resolveMissingContent($uuid);
      // Stopping propagation ensures that onConfigImporterMissingContentTwo       // will be fired on the next batch step.       $event->stopPropagation();
    }
  }

  /** * Handles the missing content event. * * @param \Drupal\Core\Config\Importer\MissingContentEvent $event * The missing content event. */

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);
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    // This should always be the final event as it will mark all content     // dependencies as resolved.     $events[ConfigEvents::IMPORT_MISSING_CONTENT][] = ['onMissingContent', -1024];
    return $events;
  }
Home | Imprint | This part of the site doesn't use cookies.