findConfigEntityDependenciesAsEntities example

$edit['uninstall[module_test]'] = TRUE;
    $this->drupalGet('admin/modules/uninstall');
    $this->submitForm($edit, 'Uninstall');
    $this->assertSession()->pageTextNotContains('Configuration deletions');
    $this->assertSession()->pageTextContains('Configuration updates');
    $this->assertSession()->pageTextContains($node_type->label());
    $this->submitForm([], 'Uninstall');
    $this->assertSession()->pageTextContains('The selected modules have been uninstalled.');

    // Uninstall node testing that the configuration that will be deleted is     // listed.     $node_dependencies = \Drupal::service('config.manager')->findConfigEntityDependenciesAsEntities('module', ['node']);
    $edit = [];
    $edit['uninstall[node]'] = TRUE;
    $this->drupalGet('admin/modules/uninstall');
    $this->submitForm($edit, 'Uninstall');
    $this->assertSession()->pageTextContains('Configuration deletions');
    $this->assertSession()->pageTextNotContains('Configuration updates');

    $entity_types = [];
    foreach ($node_dependencies as $entity) {
      $label = $entity->label() ?: $entity->id();
      $this->assertSession()->pageTextContains($label);
      
/** * {@inheritdoc} */
  public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names$dry_run = TRUE) {
    $dependency_manager = $this->getConfigDependencyManager();

    // Store the list of dependents in three separate variables. This allows us     // to determine how the dependency graph changes as entities are fixed by     // calling the onDependencyRemoval() method.
    // The list of original dependents on $names. This list never changes.     $original_dependents = $this->findConfigEntityDependenciesAsEntities($type$names$dependency_manager);

    // The current list of dependents on $names. This list is recalculated when     // calling an entity's onDependencyRemoval() method results in the entity     // changing. This list is passed to each entity's onDependencyRemoval()     // method as the list of affected entities.     $current_dependents = $original_dependents;

    // The list of dependents to process. This list changes as entities are     // processed and are either fixed or deleted.     $dependents_to_process = $original_dependents;

    
/** * Tests that calculating dependencies for system module. */
  public function testNonEntity() {
    $this->installConfig(['system']);
    $config_manager = \Drupal::service('config.manager');
    $dependents = $config_manager->findConfigEntityDependencies('module', ['system']);
    $this->assertTrue(isset($dependents['system.site']), 'Simple configuration system.site has a UUID key even though it is not a configuration entity and therefore is found when looking for dependencies of the System module.');
    // Ensure that calling     // \Drupal\Core\Config\ConfigManager::findConfigEntityDependenciesAsEntities()     // does not try to load system.site as an entity.     $config_manager->findConfigEntityDependenciesAsEntities('module', ['system']);
  }

  /** * Tests creating dependencies on configuration entities. */
  public function testDependencyManagement() {
    /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
    $config_manager = \Drupal::service('config.manager');
    $storage = $this->container->get('entity_type.manager')->getStorage('config_test');
    // Test dependencies between modules.     $entity1 = $storage->create(
      [
    $block_placement_id = mb_strtolower($block->label());
    $instance = [
      'id' => $block_placement_id,
      'settings[label]' => $block->label(),
      'region' => 'sidebar_first',
    ];
    $block = BlockContent::load(1);
    $url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default');
    $this->drupalGet($url);
    $this->submitForm($instance, 'Save block');

    $dependencies = \Drupal::service('config.manager')->findConfigEntityDependenciesAsEntities('content', [$block->getConfigDependencyName()]);
    $block_placement = reset($dependencies);
    $this->assertEquals($block_placement_id$block_placement->id(), "The block placement config entity has a dependency on the block content entity.");
  }

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