Commit 33a51373 authored by gambry's avatar gambry Committed by bircher

Issue #2855322 by gambry, tlyngej, scott_euser: Exclude specific configuration...

Issue #2855322 by gambry, tlyngej, scott_euser: Exclude specific configuration if ignored from a wildcard
parent ff557c5b
......@@ -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.<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></ul>'),
'#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]),
'#default_value' => implode(PHP_EOL, $config_ignore_settings->get('ignored_config_entities')),
'#size' => 60,
];
......
......@@ -19,6 +19,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* )
*/
class IgnoreFilter extends ConfigFilterBase implements ContainerFactoryPluginInterface {
const FORCE_EXCLUSION_PREFIX = '~';
/**
* The active configuration storage.
......@@ -79,6 +81,11 @@ class IgnoreFilter extends ConfigFilterBase implements ContainerFactoryPluginInt
return FALSE;
}
// If the string is an excluded config, don't ignore it.
if (in_array(static::FORCE_EXCLUSION_PREFIX . $config_name, $this->configuration['ignored'], TRUE)) {
return FALSE;
}
foreach ($this->configuration['ignored'] as $config_ignore_setting) {
// Check if the last character in the string is an asterisk.
// If so, it means that it is a wildcard.
......
......@@ -2,6 +2,7 @@
namespace Drupal\config_ignore\Tests;
use Drupal\config_ignore\ConfigImporterIgnore;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Serialization\Yaml;
......@@ -103,4 +104,87 @@ 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()),
];
// @TODO: Test the hook differently, single import is not ignored.
// // Submit a new single item config, with the changes.
// $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
//
// $this->drupalPostForm(NULL, [], 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()),
];
// @TODO: Test the hook differently, single import is not ignored.
// // Submit a new single item config, with the changes.
// $this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
//
// $this->drupalPostForm(NULL, [], t('Confirm'));
//
// // Validate if the title from the imported config was imported.
// $this->assertText('Import has changed title');
}
}
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