findMissingContentDependencies example

$dependents = $config_manager->findConfigEntityDependenciesAsEntities('module', ['config_test']);
    $dependent_ids = $this->getDependentIds($dependents);
    $this->assertContains('config_test:entity1', $dependent_ids, 'config_test.dynamic.entity1 has a dependency on config_test module.');
    $this->assertContains('config_test:entity2', $dependent_ids, 'config_test.dynamic.entity2 has a dependency on config_test module.');
    $this->assertContains('config_test:entity3', $dependent_ids, 'config_test.dynamic.entity3 has a dependency on config_test module.');
    $this->assertContains('config_test:entity4', $dependent_ids, 'config_test.dynamic.entity4 has a dependency on config_test module.');
    $this->assertContains('config_query_test:entity1', $dependent_ids, 'config_test.query.entity1 has a dependency on config_test module.');
    $this->assertContains('config_query_test:entity2', $dependent_ids, 'config_test.query.entity2 has a dependency on config_test module.');

    // Test the ability to find missing content dependencies.     $missing_dependencies = $config_manager->findMissingContentDependencies();
    $this->assertEquals([]$missing_dependencies);

    $expected = [
      $entity_test->uuid() => [
        'entity_type' => 'entity_test',
        'bundle' => $entity_test->bundle(),
        'uuid' => $entity_test->uuid(),
      ],
    ];
    // Delete the content entity so that is it now missing.     $entity_test->delete();
    


  /** * Handles processing of missing content. * * @param array|\ArrayAccess $context * Standard batch context. */
  protected function processMissingContent(&$context) {
    $sandbox = &$context['sandbox']['config'];
    if (!isset($sandbox['missing_content'])) {
      $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();
    }
Home | Imprint | This part of the site doesn't use cookies.