Commit 94aa8d94 authored by tlyngej's avatar tlyngej Committed by tlyngej

Issue #2863446 by tlyngej, arknoll: More advanced wildcards

parent e57c3e9d
......@@ -125,22 +125,9 @@ class ConfigImporterIgnore {
}
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.
if (Unicode::substr($config_ignore_setting, -1) == static::INCLUDE_SUFFIX) {
// Remove the asterisk character from the end of the string.
$config_ignore_setting = rtrim($config_ignore_setting, static::INCLUDE_SUFFIX);
// Test if the start of the config, we are checking, are matching
// the $config_ignore_setting string. If it is a match, mark
// that config name to be ignored.
if (Unicode::substr($config_name, 0, strlen($config_ignore_setting)) == $config_ignore_setting) {
return TRUE;
}
}
// If string does not contain an asterisk in the end, just compare
// the two strings, and if they match, mark that config name to be
// ignored.
elseif ($config_name == $config_ignore_setting) {
// Test if the config_name is in the ignore list using a shell like
// validation function to test the config_ignore_setting pattern.
if (fnmatch($config_ignore_setting, $config_name)) {
return TRUE;
}
}
......
......@@ -40,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.<br />Examples: <ul><li>user.settings</li><li>views.settings</li><li>contact.settings</li><li>webform.webform.* (will ignore all config entities that starts with <em>webform.webform</em>)</li><li>* (will ignore everything)</li><li>@force_importwebform.webform.contact (will force import for this configuration, even if ignored by a wildcard)</li></ul>', ['@force_import' => ConfigImporterIgnore::FORCE_EXCLUSION_PREFIX]),
'#description' => $this->t('One configuration name per line.<br />Examples: <ul><li>user.settings</li><li>views.settings</li><li>contact.settings</li><li>webform.webform.* (will ignore all config entities that starts with <em>webform.webform</em>)</li><li>*.contact_message.custom_contact_form.* (will ignore all config entities that starts with <em>.contact_message.custom_contact_form.</em> like fields attached to a custom contact form)</li><li>* (will ignore everything)</li><li>~webform.webform.contact (will force import for this configuration, even if ignored by a wildcard)</li></ul>'),
'#default_value' => implode(PHP_EOL, $config_ignore_settings->get('ignored_config_entities')),
'#size' => 60,
];
......
......@@ -77,7 +77,7 @@ class ConfigIgnoreTest extends WebTestBase {
// 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 ignored upon config import.
// Set the system.site:name to be ignored using system.*.
$this->config('config_ignore.settings')->set('ignored_config_entities', ['system.' . ConfigImporterIgnore::INCLUDE_SUFFIX])->save();
// Assemble a change that will try and override the current value.
......@@ -100,6 +100,29 @@ class ConfigIgnoreTest extends WebTestBase {
// Validate that the user gets a message about what has been ignored.
$this->assertText('The following config entity was ignored');
// Run the same test, but with *.site.
$this->config('config_ignore.settings')->set('ignored_config_entities', [ConfigImporterIgnore::INCLUDE_SUFFIX . '.site'])->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 rejected.
$this->assertText('Test import');
// Validate that the user gets a message about what has been ignored.
$this->assertText('The following config entity was ignored');
}
/**
......
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