-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE-1: Save settings. Some UI improvements
- Loading branch information
1 parent
3b05c80
commit 15a090a
Showing
8 changed files
with
88 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
settings-form: | ||
version: 1.x | ||
js: | ||
js/gdpr-dumper.js: {} | ||
dependencies: | ||
- core/jquery | ||
- core/drupal.form | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
gdpr_dumper.settings: | ||
title: 'GDPR dumper' | ||
description: 'Configure GDPR dumper drush command' | ||
parent: system.admin_config_development | ||
route_name: gdpr_dumper.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
administer gdpr dumper: | ||
title: 'Administer gdpr dumper' | ||
description: 'Allow to configure the gdpr dumper drush command' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(function($, Drupal) { | ||
|
||
Drupal.behaviors.gdprDumperSummary = { | ||
attach: function (context, settings) { | ||
// Display the action in the vertical tab summary. | ||
$(context).find('details[data-table-summary]').drupalSetSummary(function(context) { | ||
return Drupal.checkPlain($(context).data('table-summary')); | ||
}); | ||
|
||
} | ||
} | ||
|
||
})(jQuery, Drupal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,8 @@ protected function getEditableConfigNames() { | |
*/ | ||
public function buildForm(array $form, FormStateInterface $form_state) { | ||
$replacements = $this->settings->get('gdpr_replacements'); | ||
$empty_tables = $this->settings->get('empty_tables'); | ||
|
||
$database_tables = $this->databaseManager->getTableColumns(); | ||
$db_schema = $this->connection->schema(); | ||
$schema_handles_db_comments = \is_callable([$db_schema, 'getComment']); | ||
|
@@ -102,26 +104,32 @@ public function buildForm(array $form, FormStateInterface $form_state) { | |
|
||
$form['replacements'] = [ | ||
'#tree' => TRUE, | ||
'#attached' => [ | ||
'library' => ['gdpr_dumper/settings-form'] | ||
], | ||
]; | ||
|
||
foreach ($replacements as $table => $columns) { | ||
if (isset($database_tables[$table])) { | ||
$table_summary = $schema_handles_db_comments ? $db_schema->getComment($table) : '-'; | ||
$form['replacements'][$table] = [ | ||
'#type' => 'details', | ||
'#title' => $table, | ||
'#group' => 'advanced', | ||
'#attributes' => [ | ||
'data-table-summary' => $table_summary, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
robiningelbrecht
Author
Owner
|
||
], | ||
]; | ||
|
||
$form['replacements'][$table]['columns'] = [ | ||
'#type' => 'table', | ||
'#caption' => $table_summary, | ||
'#header' => [ | ||
['data' => $this->t('Field')], | ||
['data' => $this->t('Type')], | ||
['data' => $this->t('Description')], | ||
['data' => $this->t('Apply anonymization')], | ||
], | ||
// @todo: attach this in JS. | ||
//'#title' => $schema_handles_db_comments ? $db_schema->getComment($table) : NULL, | ||
]; | ||
|
||
foreach ($database_tables[$table] as $column_name => $column_properties) { | ||
|
@@ -150,6 +158,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { | |
'#type' => 'checkbox', | ||
'#title' => $this->t('Empty this table'), | ||
'#button_type' => 'secondary', | ||
'#default_value' => isset($empty_tables[$table]) ? $empty_tables[$table] : FALSE, | ||
]; | ||
} | ||
} | ||
|
@@ -171,6 +180,9 @@ public function submitAddTable(array &$form, FormStateInterface $form_state) { | |
$replacements[$table] = []; | ||
} | ||
|
||
// Order tables alphabetically before saving. | ||
ksort($replacements); | ||
|
||
// Update config. | ||
$this->settings->set('gdpr_replacements', $replacements)->save(); | ||
$this->messenger() | ||
|
@@ -184,6 +196,7 @@ public function submitAddTable(array &$form, FormStateInterface $form_state) { | |
public function submitForm(array &$form, FormStateInterface $form_state) { | ||
$settings = [ | ||
'gdpr_replacements' => [], | ||
'empty_tables' => [], | ||
]; | ||
|
||
$replacements = $form_state->getValue('replacements'); | ||
|
@@ -193,11 +206,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) { | |
if (!empty($column['anonymization'])) { | ||
$settings['gdpr_replacements'][$table_name][$column_name]['formatter'] = $column['anonymization']; | ||
} | ||
} | ||
}; | ||
$settings['empty_tables'][$table_name] = $properties['empty']; | ||
} | ||
|
||
// @todo: order tables alphabetically before saving. | ||
// @todo: save settings if driver config is moved out of config file. | ||
// Save settings. | ||
$this->settings->set('gdpr_replacements', $settings['gdpr_replacements']) | ||
->set('empty_tables', $settings['empty_tables'])->save(); | ||
|
||
parent::submitForm($form, $form_state); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We should probably ensure
$table_summary
is safe markup.