Commit 1ce77ccd authored by tlyngej's avatar tlyngej

Initial commit.

parents
Config Ignore
=============
INTRODUCTION
------------
Ever experienced that your sites configuration was overridden by the configuration on the filesystem, when doing a
`drush cim`?
Not anymore!
This modules is a tool to let you keep the configuration you want, in place.
REQUIREMENTS
------------
You will need the `config` module, from D8 Core, to be enabled.
INSTALLATION
------------
Consult https://www.drupal.org/docs/8/extending-drupal-8/installing-contributed-modules-find-import-enable-configure-drupal-8
to see how to install and manage modules in Drupal 8.
CONFIGURATION
-------------
Go to `admin/config/development/configuration/ignore` to set what configuration you want to ignore upon import.
For now, this module only supports changes/updates to existing configuration. Configuration marked for deletion or
creation will still be deleted or created.
This module do not support changes in the `core.extension` yet. It might work, it might not.
MAINTAINERS
-----------
Current maintainers:
* Tommy Lynge Jørgensen (TLyngeJ) - https://www.drupal.org/u/tlyngej
\ No newline at end of file
{
"name": "drupal/config_ignore",
"description": "Ignore certain configuration during import.",
"type": "drupal-module",
"homepage": "http://drupal.org/project/config_ignore",
"authors": [
{
"name": "Tommy Lynge Jørgensen",
"email": "tlyngej@gmail.com",
"homepage": "https://github.com/tlyngej",
"role": "Maintainer"
}
],
"support": {
"issues": "http://drupal.org/project/config_ignore",
"irc": "irc://irc.freenode.org/drupal-contribute",
"source": "http://cgit.drupalcode.org/config_ignore"
},
"license": "GPL-2.0+",
"minimum-stability": "dev",
"require": { }
}
ignored_config_entities: { }
dependencies:
module:
- config_ignore
enforced:
module:
- config_ignore
\ No newline at end of file
config_ignore.settings:
type: config_object
label: 'Config Ignore Settings'
mapping:
settings_to_ignore:
type: sequence
label: 'List of ignored configurations'
sequence:
type: string
\ No newline at end of file
name: Config Ignore
type: module
description: Ignore certain configuration durin import
core: 8.x
package: Other
dependencies:
- config
config_ignore.settings:
title: 'Config Ignore Settings'
route_name: 'config_ignore.settings'
description: 'List all settings to ignore'
parent: system.admin_structure
weight: 90
config_ignore.settings:
route_name: 'config_ignore.settings'
title: 'Config Split'
base_route: config.sync
weight: 99
<?php
/**
* @file
* Hooks implemented by the config_ignore module.
*/
use Drupal\Core\Config\ConfigImporter;
/**
* Implements hook_config_import_steps_alter().
*/
function config_ignore_config_import_steps_alter(&$sync_steps, ConfigImporter $config_importer) {
array_unshift($sync_steps, ['Drupal\config_ignore\ConfigImporterIgnore', 'preImport']);
array_push($sync_steps, ['Drupal\config_ignore\ConfigImporterIgnore', 'postImport']);
}
config_ignore.settings:
path: '/admin/config/development/configuration/ignore'
defaults:
_form: '\Drupal\config_ignore\Form\Settings'
_title: 'Config Ignore Settings'
requirements:
_permission: 'import configuration'
\ No newline at end of file
<?php
namespace Drupal\config_ignore;
use Drupal\Core\Config\ConfigImporter;
use Drupal\user\SharedTempStore;
/**
* Class ConfigImporterIgnore.
*
* @package Drupal\config_ignore
*/
class ConfigImporterIgnore {
/**
* Gather config that we want to keep.
*
* Saves the values, that are to be ignored, so that we can put them back in
* later on.
*
* @param array $context
* Context of the config import.
* @param ConfigImporter $config_importer
* Config importer object.
*/
public static function preImport(&$context, ConfigImporter $config_importer) {
$config_to_ignore = [];
$config_ignore_settings = \Drupal::config('config_ignore.settings')->get('ignored_config_entities');
foreach (['delete', 'create', 'rename', 'update'] as $op) {
// For now, we only support updates.
foreach ($config_importer->getUnprocessedConfiguration($op) as $config) {
if (in_array($config, $config_ignore_settings)) {
$config_to_ignore[$op][$config] = \Drupal::config($config)
->getRawData();
}
}
// We do not support core.extension.
unset($config_to_ignore[$op]['core.extension']);
}
/** @var SharedTempStore $temp_store */
$temp_store = \Drupal::service('user.shared_tempstore')->get('config_ignore');
$temp_store->set('config_to_ignore', $config_to_ignore);
$context['finished'] = 1;
}
/**
* Replace the overridden values with the original ones.
*
* @param array $context
* Context of the config import.
* @param ConfigImporter $config_importer
* Config importer object.
*/
public static function postImport(&$context, ConfigImporter $config_importer) {
/** @var SharedTempStore $temp_store */
$temp_store = \Drupal::service('user.shared_tempstore')->get('config_ignore');
$config_to_ignore = $temp_store->get('config_to_ignore');
foreach ($config_to_ignore as $op) {
foreach ($op as $config_name => $config) {
/** @var \Drupal\Core\Config\Config $config_to_restore */
$config_to_restore = \Drupal::service('config.factory')->getEditable($config_name);
$config_to_restore->setData($config)->save();
}
}
$context['finished'] = 1;
$temp_store->delete('config_to_ignore');
}
}
<?php
namespace Drupal\config_ignore\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a setting UI for Config Ignore.
*
* @package Drupal\config_ignore\Form
*/
class Settings extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'config_ignore.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'config_ignore_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config_ignore_settings = $this->config('config_ignore.settings');
$form['ignored_config_entities'] = [
'#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></ul>'),
'#default_value' => implode('\n', $config_ignore_settings->get('ignored_config_entities')),
'#size' => 60,
'#maxlength' => 128,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$config_ignore_settings = $this->config('config_ignore.settings');
$config_ignore_settings->set('ignored_config_entities', explode('\n', $values['ignored_config_entities']));
$config_ignore_settings->save();
parent::submitForm($form, $form_state);
}
}
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