getDependentEntities example

use Drupal\Core\Config\Entity\ConfigDependencyManager;

/** * Tests the ConfigDependencyManager class. * * @group Config */
class ConfigDependencyManagerTest extends UnitTestCase {

  public function testNoConfiguration() {
    $dep_manger = new ConfigDependencyManager();
    $this->assertEmpty($dep_manger->getDependentEntities('config', 'config_test.dynamic.entity_id:745b0ce0-aece-42dd-a800-ade5b8455e84'));
  }

  public function testNoConfigEntities() {
    $dep_manger = new ConfigDependencyManager();
    $dep_manger->setData([
      'simple.config' => [
        'key' => 'value',
      ],
    ]);
    $this->assertEmpty($dep_manger->getDependentEntities('config', 'config_test.dynamic.entity_id:745b0ce0-aece-42dd-a800-ade5b8455e84'));

    


  /** * {@inheritdoc} */
  public function findConfigEntityDependencies($type, array $names, ConfigDependencyManager $dependency_manager = NULL) {
    if (!$dependency_manager) {
      $dependency_manager = $this->getConfigDependencyManager();
    }
    $dependencies = [];
    foreach ($names as $name) {
      $dependencies[] = $dependency_manager->getDependentEntities($type$name);
    }
    return array_merge(...$dependencies);
  }

  /** * {@inheritdoc} */
  public function findConfigEntityDependenciesAsEntities($type, array $names, ConfigDependencyManager $dependency_manager = NULL) {
    $dependencies = $this->findConfigEntityDependencies($type$names$dependency_manager);
    $entities = [];
    $definitions = $this->entityTypeManager->getDefinitions();
    
    // new configuration that can be installed.     if ($profile_storage) {
      $config_to_create = $profile_storage->readMultiple($list) + $config_to_create;
    }
    // Sort $config_to_create in the order of the least dependent first.     $dependency_manager = new ConfigDependencyManager();
    $dependency_manager->setData($config_to_create);
    $config_to_create = array_merge(array_flip($dependency_manager->sortAll())$config_to_create);
    if (!empty($dependency)) {
      // In order to work out dependencies we need the full config graph.       $dependency_manager->setData($this->getActiveStorages()->readMultiple($existing_config) + $config_to_create);
      $dependencies = $dependency_manager->getDependentEntities(key($dependency)reset($dependency));
    }

    foreach ($config_to_create as $config_name => $data) {
      // Remove configuration where its dependencies cannot be met.       $remove = !$this->validateDependencies($config_name$data$enabled_extensions$all_config);
      // Remove configuration that is not dependent on $dependency, if it is       // defined.       if (!$remove && !empty($dependency)) {
        $remove = !isset($dependencies[$config_name]);
      }

      

  private function getDependentConfigNames() {
    $modules = $this->getExcludedModules();

    $dependencyManager = $this->manager->getConfigDependencyManager();
    $config = [];

    // Find all the configuration depending on the excluded modules.     foreach ($modules as $module) {
      foreach ($dependencyManager->getDependentEntities('module', $module) as $dependent) {
        $config[] = $dependent->getConfigDependencyName();
      }
      $config = array_merge($config$this->activeStorage->listAll($module . '.'));
    }

    // Find all configuration that depends on the configuration found above.     foreach ($this->manager->findConfigEntityDependencies('config', array_unique($config)) as $dependent) {
      $config[] = $dependent->getConfigDependencyName();
    }

    return array_unique($config);
  }
Home | Imprint | This part of the site doesn't use cookies.