Commit 2b89ba3e authored by tlyngej's avatar tlyngej Committed by tlyngej

Issue #2845024 by tlyngej, jrockowitz: Add hook_config_ignore_alter(&$names)

parent 3444442b
<?php
/**
* @file
* Hooks specific to the Config Ignore module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the list of config entities that should be ignored.
*/
function hook_config_ignore_settings_alter(array &$settings) {
$settings[] = 'system.site';
$settings[] = 'field.*';
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -27,6 +27,7 @@ class ConfigImporterIgnore {
public static function preImport(array &$context, ConfigImporter $config_importer) {
$config_to_ignore = [];
$config_ignore_settings = \Drupal::config('config_ignore.settings')->get('ignored_config_entities');
\Drupal::moduleHandler()->invokeAll('config_ignore_settings_alter', [&$config_ignore_settings]);
foreach (['delete', 'create', 'rename', 'update'] as $op) {
// For now, we only support updates.
if ($op == 'update') {
......
<?php
namespace Drupal\config_ignore\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Serialization\Yaml;
/**
* Test hooks that this module implements.
*
* This must be a simpletest test as it does not seem that the PHPUnit
* implementation for Drupal supports batch processing yet.
*
* @package Drupal\config_ignore\Tests
*
* @group config_ignore
*/
class ConfigIgnoreHookTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['config_ignore_hook_test'];
/**
* The profile to install as a basis for testing.
*
* We need to change it form the standard 'testing' profile as that will not
* print the title on the page, which we use for testing.
*
* @var string
*/
protected $profile = 'minimal';
/**
* Verify that hook_config_ignore_settings_alter are getting called.
*/
public function testSettingsAlterHook() {
// 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 title')->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, [], t('Confirm'));
// Validate if the title from the imported config was rejected, due to the
// hook implemented in the `config_ignore_hook_test` module.
$this->drupalGet('<front>');
$this->assertText('Test import title');
}
}
name: Config Ignore Hook Test
type: module
description: Module that implements all the hook from Config Ignore for testing purposes
core: 8.x
package: Configuration
dependencies:
- config_ignore
<?php
/**
* @file
* Module that implements all the hook from Config Ignore for testing purposes.
*/
/**
* Implements hook_config_ignore_settings_alter().
*/
function config_ignore_hook_test_config_ignore_settings_alter(array &$settings) {
$settings[] = 'system.site';
}
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