ConfigDependencyManager example



    $all_config = array_merge($existing_config$list);
    $all_config = array_combine($all_config$all_config);
    $config_to_create = $storage->readMultiple($list);
    // Check to see if the corresponding override storage has any overrides or     // 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);
      
if (is_dir($schema_dir)) {
      // Refresh the schema cache if uninstalling an extension that provides       // configuration schema.       $this->typedConfigManager->clearCachedDefinitions();
    }
  }

  /** * {@inheritdoc} */
  public function getConfigDependencyManager() {
    $dependency_manager = new ConfigDependencyManager();
    // Read all configuration using the factory. This ensures that multiple     // deletes during the same request benefit from the static cache. Using the     // factory also ensures configuration entity dependency discovery has no     // dependencies on the config entity classes. Assume data with UUID is a     // config entity. Only configuration entities can be depended on so we can     // ignore everything else.     $data = array_map(function D$config) {
      $data = $config->get();
      if (isset($data['uuid'])) {
        return $data;
      }
      
$source_storage = $this->getSourceStorage($collection);
    $target_storage = $this->getTargetStorage($collection);
    $target_names = $target_storage->listAll();
    $source_names = $source_storage->listAll();
    // Prime the static caches by reading all the configuration in the source     // and target storages.     $target_data = $target_storage->readMultiple($target_names);
    $source_data = $source_storage->readMultiple($source_names);
    // If the collection only supports simple configuration do not use     // configuration dependencies.     if ($collection == StorageInterface::DEFAULT_COLLECTION) {
      $dependency_manager = new ConfigDependencyManager();
      $this->targetNames[$collection] = $dependency_manager->setData($target_data)->sortAll();
      $this->sourceNames[$collection] = $dependency_manager->setData($source_data)->sortAll();
    }
    else {
      $this->targetNames[$collection] = $target_names;
      $this->sourceNames[$collection] = $source_names;
    }
  }

  /** * Creates a rename name from the old and new names for the object. * * @param string $old_name * The old configuration object name. * @param string $new_name * The new configuration object name. * * @return string * The configuration change name that encodes both the old and the new name. * * @see \Drupal\Core\Config\StorageComparerInterface::extractRenameNames() */
use Drupal\Tests\UnitTestCase;
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'));

    

class ConfigDependencyManagerTest extends UnitTestCase {

  /** * @dataProvider providerTestSortAll */
  public function testSortAll(array $data, array $expected_order) {
    $dependency_manager = new ConfigDependencyManager();
    $dependency_manager->setData($data);
    $this->assertEquals($expected_order$dependency_manager->sortAll());
  }

  public function providerTestSortAll() {
    $datasets[] = [
      [
        'provider.entity_b' => [],
        'provider.entity_a' => [],
      ],
      ['provider.entity_a', 'provider.entity_b'],
    ];
Home | Imprint | This part of the site doesn't use cookies.