Commit 6ce970c0 authored by tlyngej's avatar tlyngej

Add overview of ignore content on the config sync. page

parent 5fcb8501
......@@ -6,10 +6,66 @@
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Url;
/**
* Implements hook_form_FORM_ID_alter().
*/
function config_ignore_form_config_admin_import_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// @TODO: list the ignored config.
// Load Services that we need.
$config_directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$stock_storage_sync = new FileStorage($config_directory, StorageInterface::DEFAULT_COLLECTION);
$active_storage_sync = \Drupal::service('config.storage.sync');
$storage = \Drupal::service('config.storage');
$config_manager = \Drupal::service('config.manager');
// Create two StorageComparer objects, one with the filter enabled and one
// as without. We will compare them later to see what changes that has been
// ignored.
$unfiltered_storage_compare = new StorageComparer($stock_storage_sync, $storage, $config_manager);
$filtered_storage_compare = new StorageComparer($active_storage_sync, $storage, $config_manager);
$unfiltered_storage_compare->createChangelist();
$filtered_storage_compare->createChangelist();
// Create an array of the changes with the filter on.
$config_changes = [];
foreach ($filtered_storage_compare->getChangelist() as $config_names) {
foreach ($config_names as $config_name) {
$config_changes[] = $config_name;
}
}
foreach ($unfiltered_storage_compare->getAllCollectionNames() as $collection) {
foreach ($unfiltered_storage_compare->getChangelist(NULL, $collection) as $config_change_type => $config_names) {
foreach ($config_names as $config_name) {
// If the config name exists here, but not in the $config_changes array
// the it's because it's getting ignored.
if (!in_array($config_name, $config_changes)) {
$ignored_config_entities[] = [
$config_name,
$config_change_type,
];
}
}
}
}
// Build a table of changes that are not going to happen, due to the ignored
// config entities.
if (!empty($ignored_config_entities)) {
$form['ignored'] = [
'#type' => 'table',
'#header' => ['Config name', 'Action'],
'#caption' => t('The following configuration entities are ignored due to the <a href="@url">Config Ignore Settings</a> and therefore not displayed in the list above', [
'@url' => Url::fromRoute('config_ignore.settings')
->toString()
]),
'#rows' => $ignored_config_entities,
];
}
}
......@@ -2,7 +2,6 @@
namespace Drupal\config_ignore\Plugin\ConfigFilter;
use Drupal\Component\Utility\Unicode;
use Drupal\config_filter\Plugin\ConfigFilterBase;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......
......@@ -22,7 +22,7 @@ class ConfigIgnoreTest extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['config_ignore'];
public static $modules = ['config_ignore', 'config', 'config_filter'];
/**
* Verify that the Sync. table gets update with appropriate ignore actions.
......@@ -34,30 +34,37 @@ class ConfigIgnoreTest extends BrowserTestBase {
$this->config('system.site')->set('name', 'Test import')->save();
$this->config('system.date')->set('first_day', '0')->save();
$this->config('config_ignore.settings')->set('ignored_config_entities', ['system.site'])->save();
// @TODO: Test this differently, I am not sure this is the best way.
// $destination = CONFIG_SYNC_DIRECTORY;
// $destination_dir = config_get_config_directory($destination);
// /** @var CachedStorage $source_storage */
// $source_storage = \Drupal::service('config.storage');
// $destination_storage = new FileStorage($destination_dir);
// foreach ($source_storage->listAll() as $name) {
// $destination_storage->write($name, $source_storage->read($name));
// }
// @TODO: Test the ignored config differently, the table is not altered.
// // Login with a user that has permission to sync. config.
// $this->drupalLogin($this->drupalCreateUser(['synchronize configuration']));
//
// // Change the site name, which is supposed to look as an ignored change
// // in on the sync. page.
// $this->config('system.site')->set('name', 'Test import with changed title')->save();
// $this->config('system.date')->set('first_day', '1')->save();
//
// // Validate that the sync. table informs the user that the config will be
// // ignored.
// $this->drupalGet('admin/config/development/configuration');
// $this->assertSession()->responseContains('✔');
// $this->assertSession()->responseContains('✖');
$destination = CONFIG_SYNC_DIRECTORY;
$destination_dir = config_get_config_directory($destination);
/** @var CachedStorage $source_storage */
$source_storage = \Drupal::service('config.storage');
$destination_storage = new FileStorage($destination_dir);
foreach ($source_storage->listAll() as $name) {
$destination_storage->write($name, $source_storage->read($name));
}
// Login with a user that has permission to sync. config.
$this->drupalLogin($this->drupalCreateUser(['synchronize configuration']));
// Change the site name, which is supposed to look as an ignored change
// in on the sync. page.
$this->config('system.site')->set('name', 'Test import with changed title')->save();
$this->config('system.date')->set('first_day', '1')->save();
// Validate that the sync. table informs the user that the config will be
// ignored.
$this->drupalGet('admin/config/development/configuration');
$this->assertSession()->linkExists('Config Ignore Settings');
/** @var \Behat\Mink\Element\NodeElement[] $table_content */
$table_content = $this->xpath('//table[@id="edit-ignored"]//td');
$table_values = [];
foreach ($table_content as $item) {
$table_values[] = $item->getHtml();
}
$this->assertTrue(in_array('system.site', $table_values));
}
}
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