getMissingContent 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];
    
$missing_content = $this->configManager->findMissingContentDependencies();
      $sandbox['missing_content']['data'] = $missing_content;
      $sandbox['missing_content']['total'] = count($missing_content);
    }
    else {
      $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($event, ConfigEvents::IMPORT_MISSING_CONTENT);
      $sandbox['missing_content']['data'] = $event->getMissingContent();
    }
    $current_count = count($sandbox['missing_content']['data']);
    if ($current_count) {
      $context['message'] = $this->t('Resolving missing content');
      $context['finished'] = ($sandbox['missing_content']['total'] - $current_count) / $sandbox['missing_content']['total'];
    }
    else {
      $context['finished'] = 1;
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.