public function testWithDependencies()
 {
     $values = array('uuid' => '60db47f4-54fb-4c86-a439-5769fbda4bd1', 'dependencies' => array('module' => array('node', 'views'), 'config' => array('config_test.dynamic.entity_id:745b0ce0-aece-42dd-a800-ade5b8455e84')));
     $dep = new ConfigEntityDependency('config_test.dynamic.entity_id', $values);
     $this->assertEquals(array(), $dep->getDependencies('theme'));
     $this->assertEquals(array('config_test.dynamic.entity_id:745b0ce0-aece-42dd-a800-ade5b8455e84'), $dep->getDependencies('config'));
     $this->assertEquals(array('node', 'views', 'config_test'), $dep->getDependencies('module'));
     $this->assertTrue($dep->hasDependency('module', 'config_test'));
     $this->assertTrue($dep->hasDependency('module', 'views'));
     $this->assertTrue($dep->hasDependency('module', 'node'));
     $this->assertFalse($dep->hasDependency('module', 'block'));
     $this->assertTrue($dep->hasDependency('config', 'config_test.dynamic.entity_id:745b0ce0-aece-42dd-a800-ade5b8455e84'));
     $this->assertFalse($dep->hasDependency('config', 'config_test.dynamic.another_id:7dfa5cb7-2248-4d52-8c00-cd8e02d1e78e'));
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function installOptionalConfig(StorageInterface $storage = NULL, $dependency = [])
 {
     $profile = $this->drupalGetProfile();
     $optional_profile_config = [];
     if (!$storage) {
         // Search the install profile's optional configuration too.
         $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE);
         // The extension install storage ensures that overrides are used.
         $profile_storage = NULL;
     } elseif (isset($profile)) {
         // Creates a profile storage to search for overrides.
         $profile_install_path = $this->drupalGetPath('module', $profile) . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
         $profile_storage = new FileStorage($profile_install_path, StorageInterface::DEFAULT_COLLECTION);
         $optional_profile_config = $profile_storage->listAll();
     } else {
         // Profile has not been set yet. For example during the first steps of the
         // installer or during unit tests.
         $profile_storage = NULL;
     }
     $enabled_extensions = $this->getEnabledExtensions();
     $existing_config = $this->getActiveStorages()->listAll();
     $list = array_unique(array_merge($storage->listAll(), $optional_profile_config));
     $list = array_filter($list, function ($config_name) use($existing_config) {
         // Only list configuration that:
         // - does not already exist
         // - is a configuration entity (this also excludes config that has an
         //   implicit dependency on modules that are not yet installed)
         return !in_array($config_name, $existing_config) && $this->configManager->getEntityTypeIdByName($config_name);
     });
     $all_config = array_merge($existing_config, $list);
     $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;
     }
     foreach ($config_to_create as $config_name => $data) {
         // Exclude configuration where its dependencies cannot be met.
         if (!$this->validateDependencies($config_name, $data, $enabled_extensions, $all_config)) {
             unset($config_to_create[$config_name]);
         } elseif (!empty($dependency)) {
             // Create a light weight dependency object to check dependencies.
             $config_entity = new ConfigEntityDependency($config_name, $data);
             if (!$config_entity->hasDependency(key($dependency), reset($dependency))) {
                 unset($config_to_create[$config_name]);
             }
         }
     }
     if (!empty($config_to_create)) {
         $this->createConfiguration(StorageInterface::DEFAULT_COLLECTION, $config_to_create, TRUE);
     }
 }