Commit fb05cb4b authored by catch's avatar catch

Issue #2930996 by alexpott, mtodor, chr.fritsch, Berdir: Config installer...

Issue #2930996 by alexpott, mtodor, chr.fritsch, Berdir: Config installer doens't install possible installable config
parent a4560fd0
......@@ -4,7 +4,6 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Config\Entity\ConfigDependencyManager;
use Drupal\Core\Config\Entity\ConfigEntityDependency;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ConfigInstaller implements ConfigInstallerInterface {
......@@ -204,16 +203,19 @@ public function installOptionalConfig(StorageInterface $storage = NULL, $depende
$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 $dependency is defined, remove configuration that does not have a
// matching dependency.
// Remove configuration that is not dependent on $dependency, if it is
// defined.
if (!$remove && !empty($dependency)) {
// Create a light weight dependency object to check dependencies.
$config_entity = new ConfigEntityDependency($config_name, $data);
$remove = !$config_entity->hasDependency(key($dependency), reset($dependency));
$remove = !isset($dependencies[$config_name]);
}
if ($remove) {
......
id: dependency_for_unmet2
label: 'Other module test to test optional config installation'
weight: 0
style: ''
status: true
langcode: en
protected_property: Default
id: other_module_test_optional_entity_unmet2
label: 'Other module test to test optional config installation'
weight: 0
style: ''
status: true
langcode: en
protected_property: Default
dependencies:
enforced:
config:
- config_test.dynamic.dependency_for_unmet2
......@@ -62,12 +62,29 @@ public function testInstallOtherModuleFirst() {
$this->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.');
$this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.');
$this->installModule('config_test_language');
$this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet2', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are not met is not created.');
$this->installModule('config_install_dependency_test');
$this->assertTrue(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are met is now created.');
// Although the following configuration entity's are now met it is not
// installed because it does not have a direct dependency on the
// config_install_dependency_test module.
$this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not created.');
// The following configuration entity's dependencies are now met. It is
// indirectly dependent on the config_install_dependency_test module because
// it has a dependency on the config_test.dynamic.dependency_for_unmet2
// configuration provided by that module and, therefore, should be created.
$this->assertTrue(entity_load('config_test', 'other_module_test_optional_entity_unmet2', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet2 whose dependencies are met is now created.');
// The following configuration entity's dependencies are now met even though
// it has no direct dependency on the module. It is indirectly dependent on
// the config_install_dependency_test module because it has a dependency on
// the config_test.dynamic.other_module_test_unmet configuration that is
// dependent on the config_install_dependency_test module and, therefore,
// should be created.
$entity = entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE);
$this->assertTrue($entity, 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is created.');
$entity->delete();
// Install another module to ensure the configuration just deleted is not
// recreated.
$this->installModule('config');
$this->assertFalse(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not installed when an unrelated module is installed.');
}
/**
......
......@@ -7,6 +7,7 @@
use Drupal\KernelTests\KernelTestBase;
use Drupal\views\Tests\ViewResultAssertionTrait;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\ViewsData;
/**
* Defines a base class for Views kernel testing.
......@@ -65,6 +66,7 @@ protected function setUpFixtures() {
// Define the schema and views data variable before enabling the test module.
$state->set('views_test_data_schema', $this->schemaDefinition());
$state->set('views_test_data_views_data', $this->viewsData());
$this->container->get('views.views_data')->clear();
$this->installConfig(['views', 'views_test_config', 'views_test_data']);
foreach ($this->schemaDefinition() as $table => $schema) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment