diff --git a/src/ConfigIgnoreConfig.php b/src/ConfigIgnoreConfig.php index fc1927f..7f9ac7d 100644 --- a/src/ConfigIgnoreConfig.php +++ b/src/ConfigIgnoreConfig.php @@ -197,6 +197,26 @@ final class ConfigIgnoreConfig { public function isIgnored(string $collection, string $name, string $direction, string $operation) { $parts = []; foreach ($this->data[$operation][$direction] as $pattern) { + // Get collection from the pattern. + $collection_pattern = '*'; + if (strpos($pattern, '|') !== FALSE) { + // Divide the pattern into collection and pattern. + [$collection_pattern, $pattern] = explode('|', $pattern, 2); + $pattern = trim($pattern); + + // If collection pattern includes a wildcard then move it to the + // config name pattern. + if ($collection_pattern[0] === '~') { + $collection_pattern = ltrim($collection_pattern, '~'); + $pattern = '~' . ltrim($pattern, '~'); + } + } + + // Skip if the collection pattern does not match. + if (!self::wildcardMatch($collection_pattern, $collection)) { + continue; + } + // Early return when the line matches. if ($pattern === '~' . $name) { return FALSE; diff --git a/src/Form/IgnoreSettingsForm.php b/src/Form/IgnoreSettingsForm.php index c050c9f..1d13362 100644 --- a/src/Form/IgnoreSettingsForm.php +++ b/src/Form/IgnoreSettingsForm.php @@ -48,6 +48,10 @@ Examples: '); $form['mode'] = [ diff --git a/tests/src/Kernel/IgnoreKernelTest.php b/tests/src/Kernel/IgnoreKernelTest.php index 287eb93..377c83a 100644 --- a/tests/src/Kernel/IgnoreKernelTest.php +++ b/tests/src/Kernel/IgnoreKernelTest.php @@ -171,12 +171,29 @@ class IgnoreKernelTest extends KernelTestBase { [], [], ]; - yield 'do not remove translation when ignored' => [ + yield 'do not remove config and translation when ignored' => [ 'simple', ['config_test.system'], - ['de' => ['config_test.system' => ['foo' => 'Neues Foo']]], + [ + '' => ['config_test.system' => ['foo' => 'New Foo']], + 'de' => ['config_test.system' => ['foo' => 'Nieuw Foo']], + ], [], - ['de' => ['config_test.system' => ['foo' => 'Neues Foo']]], + [ + '' => ['config_test.system' => ['foo' => 'New Foo']], + 'de' => ['config_test.system' => ['foo' => 'Nieuw Foo']], + ], + ]; + yield 'do not remove only de translation when ignored' => [ + 'simple', + ['language.de|config_test.system'], + [ + '' => ['config_test.system' => ['foo' => 'New Foo']], + 'de' => ['config_test.system' => ['foo' => 'Nieuw Foo']], + 'fr' => ['config_test.system' => ['foo' => 'Neues Foo']], + ], + [], + ['de' => ['config_test.system' => ['foo' => 'Nieuw Foo']]], ]; yield 'do not remove translation when key is ignored' => [ 'simple', @@ -199,6 +216,18 @@ class IgnoreKernelTest extends KernelTestBase { ['se' => ['config_test.system' => ['foo' => 'Ny foo']]], [], ]; + yield 'ignore only fr lang collection' => [ + 'simple', + ['language.fr|*'], + [], + [ + '' => ['config_test.system' => ['foo' => 'FR Bar', '404' => 'herp']], + 'fr' => ['config_test.system' => ['foo' => 'FR Bar']], + ], + [ + '' => ['config_test.system' => ['foo' => 'FR Bar', '404' => 'herp']], + ], + ]; yield 'new config is ignored' => [ 'simple', ['config_test.*'], @@ -220,6 +249,30 @@ class IgnoreKernelTest extends KernelTestBase { ], ], ]; + yield 'new collection is ignored' => [ + 'simple', + ['language.*|config_test.*'], + ['' => ['config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'E']]], + [ + '' => ['config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'N']], + 'de' => ['config_test.dynamic.exist' => ['label' => 'DE']], + ], + ['' => ['config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'N']]], + ]; + yield 'new collection is ignored except FR' => [ + 'simple', + ['language.*|config_test.*', '~language.fr|config_test.*'], + ['' => ['config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'E']]], + [ + '' => ['config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'N']], + 'de' => ['config_test.dynamic.exist' => ['label' => 'DE']], + 'fr' => ['config_test.dynamic.exist' => ['label' => 'FR']], + ], + [ + '' => ['config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'N']], + 'fr' => ['config_test.dynamic.exist' => ['label' => 'FR']], + ], + ]; yield 'new config is not ignored in lenient mode' => [ 'lenient', ['config_test.*'], @@ -434,7 +487,7 @@ class IgnoreKernelTest extends KernelTestBase { if ($data !== FALSE) { if (is_array($storage->read($name))) { // Merge nested arrays if the storage already has data. - $data = NestedArray::mergeDeep($storage->read($name), $data); + $data = NestedArray::mergeDeepArray([$storage->read($name), $data], TRUE); } $storage->write($name, $data); }