diff --git a/src/ConfigImporterIgnore.php b/src/ConfigImporterIgnore.php
index 3c47ebd..fc4ae72 100644
--- a/src/ConfigImporterIgnore.php
+++ b/src/ConfigImporterIgnore.php
@@ -13,6 +13,8 @@ use Drupal\user\SharedTempStore;
*/
class ConfigImporterIgnore {
+ const FORCE_EXCLUSION_PREFIX = '~';
+
/**
* Gather config that we want to keep.
*
@@ -115,6 +117,10 @@ class ConfigImporterIgnore {
public static function matchConfigName($config_name) {
$config_ignore_settings = \Drupal::config('config_ignore.settings')->get('ignored_config_entities');
\Drupal::moduleHandler()->invokeAll('config_ignore_settings_alter', [&$config_ignore_settings]);
+ // If the string is an excluded config, don't ignore it.
+ if (in_array(static::FORCE_EXCLUSION_PREFIX . $config_name, $config_ignore_settings, TRUE)) {
+ return FALSE;
+ }
foreach ($config_ignore_settings as $config_ignore_setting) {
// Check if the last character in the string is an asterisk.
// If so, it means that it is a wildcard.
diff --git a/src/Form/Settings.php b/src/Form/Settings.php
index 230c89c..ed77ae7 100644
--- a/src/Form/Settings.php
+++ b/src/Form/Settings.php
@@ -2,6 +2,7 @@
namespace Drupal\config_ignore\Form;
+use Drupal\config_ignore\ConfigImporterIgnore;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -39,7 +40,7 @@ class Settings extends ConfigFormBase {
'#type' => 'textarea',
'#rows' => 25,
'#title' => $this->t('Configuration entity names to ignore'),
- '#description' => $this->t('One configuration name per line.
Examples:
- user.settings
- views.settings
- contact.settings
- webform.webform.* (will ignore all config entities that starts with webform.webform)
- * (will ignore everything)
'),
+ '#description' => $this->t('One configuration name per line.
Examples: - user.settings
- views.settings
- contact.settings
- webform.webform.* (will ignore all config entities that starts with webform.webform)
- * (will ignore everything)
- @force_importwebform.webform.contact (will force import for this configuration, even if ignored by a wildcard)
', ['@force_import' => ConfigImporterIgnore::FORCE_EXCLUSION_PREFIX]),
'#default_value' => implode(PHP_EOL, $config_ignore_settings->get('ignored_config_entities')),
'#size' => 60,
];
diff --git a/src/Tests/ConfigIgnoreTest.php b/src/Tests/ConfigIgnoreTest.php
index e353250..91232bb 100644
--- a/src/Tests/ConfigIgnoreTest.php
+++ b/src/Tests/ConfigIgnoreTest.php
@@ -2,6 +2,7 @@
namespace Drupal\config_ignore\Tests;
+use Drupal\config_ignore\ConfigImporterIgnore;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Serialization\Yaml;
@@ -101,4 +102,85 @@ class ConfigIgnoreTest extends WebTestBase {
}
+ /**
+ * Verify Force Import syntax is working.
+ *
+ * This test makes sure we avoid regression issues.
+ */
+ public function testValidateForceImporting() {
+
+ // Login with a user that has permission to import config.
+ $this->drupalLogin($this->drupalCreateUser(['import configuration']));
+
+ // Set the site name to a known value that we later will try and overwrite.
+ $this->config('system.site')->set('name', 'Test import')->save();
+
+ // Set the system.site:name to be (force-) imported upon config import.
+ $settings = [ConfigImporterIgnore::FORCE_EXCLUSION_PREFIX . 'system.site'];
+ $this->config('config_ignore.settings')->set('ignored_config_entities', $settings)->save();
+
+ // Assemble a change that will try and override the current value.
+ $config = $this->config('system.site')->set('name', 'Import has changed title');
+
+ $edit = [
+ 'config_type' => 'system.simple',
+ 'config_name' => $config->getName(),
+ 'import' => Yaml::encode($config->get()),
+ ];
+
+ // Submit a new single item config, with the changes.
+ $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
+
+ $this->drupalPostForm(NULL, array(), t('Confirm'));
+
+ // Validate if the title from the imported config was imported.
+ $this->assertText('Import has changed title');
+
+ // Validate that the user does NOT get the message about configuration
+ // been ignored.
+ $this->assertNoText('The following config entity was ignored');
+
+ }
+
+ /**
+ * Verify excluded configuration works with wildcards.
+ *
+ * This test cover the scenario where a wildcard matches a specific
+ * configuration, but that's still imported due exclusion.
+ */
+ public function testValidateForceImportingWithWildcard() {
+
+ // Login with a user that has permission to import config.
+ $this->drupalLogin($this->drupalCreateUser(['import configuration']));
+
+ // Set the site name to a known value that we later will try and overwrite.
+ $this->config('system.site')->set('name', 'Test import')->save();
+
+ // Set system.* configs to be ignored and system.site:name to be (force-)
+ // imported upon config import.
+ $settings = [
+ 'system.*',
+ ConfigImporterIgnore::FORCE_EXCLUSION_PREFIX . 'system.site',
+ ];
+ $this->config('config_ignore.settings')->set('ignored_config_entities', $settings)->save();
+
+ // Assemble a change that will try and override the current value.
+ $config = $this->config('system.site')->set('name', 'Import has changed title');
+
+ $edit = [
+ 'config_type' => 'system.simple',
+ 'config_name' => $config->getName(),
+ 'import' => Yaml::encode($config->get()),
+ ];
+
+ // Submit a new single item config, with the changes.
+ $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
+
+ $this->drupalPostForm(NULL, array(), t('Confirm'));
+
+ // Validate if the title from the imported config was imported.
+ $this->assertText('Import has changed title');
+
+ }
+
}